Fritz Posted October 19, 2002 Posted October 19, 2002 I have a timer to count in seconds: Private counter As Integer Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick counter += 1 lblTimer.Text = counter.ToString.Format(TimeString) End Sub So far thats ok, but I would like it to start by 00:00.00. How can I do this? Quote
*Experts* Bucky Posted October 19, 2002 *Experts* Posted October 19, 2002 I'm not sure I understand what you mean, but if you swap the position of increasing counter and setting the label's Text (increase the counter last in the sub), then in the first timer tick counter will be 0. What is TimeString? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Moderators Robby Posted October 19, 2002 Moderators Posted October 19, 2002 I'm sure there's a better and shorter solution. This is really messy and long but it works. 'Declare these at the top of your page (inside the Class) Private intCounter As Integer = 0 Private intSeconds As Integer = 0 Private intMinutes As Integer = 0 Private intHours As Integer = 0 'here goes.... Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.Text = FormatCounter() End Sub Private Function FormatCounter() As String Dim sTemp As String If intCounter < 60 Then intSeconds = intCounter Else intMinutes += 1 intCounter = 0 intSeconds = 0 End If If intMinutes >= 60 Then intSeconds = 0 intCounter = 0 intMinutes = 0 intHours += 1 End If intCounter += 1 If intHours < 10 Then sTemp = "0" & intHours.ToString & ":" Else sTemp = intHours.ToString End If If intMinutes < 10 Then sTemp = sTemp & "0" & intMinutes.ToString & ":" Else sTemp = sTemp & intMinutes.ToString End If If intSeconds < 10 Then sTemp = sTemp & "0" & intSeconds.ToString Else sTemp = sTemp & intSeconds.ToString End If Return sTemp End Function Quote Visit...Bassic Software
Fritz Posted October 19, 2002 Author Posted October 19, 2002 Yeah, thanks. I can manage with that. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.