Timer
-
Hello everybody...! Anybody can tell me how should start TIMER from "00:00:00" ...? Thank you ...! :-D :-D :-D
Best Regards, Ahmad Rifai Yusuf
-
Hello everybody...! Anybody can tell me how should start TIMER from "00:00:00" ...? Thank you ...! :-D :-D :-D
Best Regards, Ahmad Rifai Yusuf
Go read MSDN. Search Google. Have you tried any of these? No? Heres a hint http://msdn2.microsoft.com/en-us/library/system.timers.timer(VS.71).aspx[^]
-
Hello everybody...! Anybody can tell me how should start TIMER from "00:00:00" ...? Thank you ...! :-D :-D :-D
Best Regards, Ahmad Rifai Yusuf
Test this code Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' supposing we have a label and it has the text 00:00:00 when the form loads ' Timer interval we can set as per requirement ' I have set it for 0-9. If you want to test upto 1 minute then change 9 by 99 and 10 by 100 s = Label1.Text.Split(":") If CInt(s(2)) >= 0 AndAlso CInt(s(2)) < 9 Then s(2) = Format(CInt(s(2)) + 1, "00") ElseIf CInt(s(2)) = 9 Then s(2) = Format(0, "00") s(1) = CInt(s(1)) + 1 s(1) = Format(CInt(s(1)), "00") End If If CInt(s(1)) = 10 Then s(0) = Format(CInt(s(0)) + 1, "00") s(1) = Format(0, "00") End If Label1.Text = s(0) & ":" & s(1) & ":" & s(2) End Sub Hope this solves the purpose.
-
Hello everybody...! Anybody can tell me how should start TIMER from "00:00:00" ...? Thank you ...! :-D :-D :-D
Best Regards, Ahmad Rifai Yusuf
I just forgot to mention one thing. Declare an string array globally like: Dim s() as String Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' supposing we have a label and it has the text 00:00:00 when the form loads ' Timer interval we can set as per requirement ' I have set it for 0-9. If you want to test upto 1 minute then change 9 by 99 and 10 by 100 s = Label1.Text.Split(":") If CInt(s(2)) >= 0 AndAlso CInt(s(2)) < 9 Then s(2) = Format(CInt(s(2)) + 1, "00") ElseIf CInt(s(2)) = 9 Then s(2) = Format(0, "00") s(1) = CInt(s(1)) + 1 s(1) = Format(CInt(s(1)), "00") End If If CInt(s(1)) = 10 Then s(0) = Format(CInt(s(0)) + 1, "00") s(1) = Format(0, "00") End If Label1.Text = s(0) & ":" & s(1) & ":" & s(2) End Sub Hope this solves the purpose.
-
Test this code Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' supposing we have a label and it has the text 00:00:00 when the form loads ' Timer interval we can set as per requirement ' I have set it for 0-9. If you want to test upto 1 minute then change 9 by 99 and 10 by 100 s = Label1.Text.Split(":") If CInt(s(2)) >= 0 AndAlso CInt(s(2)) < 9 Then s(2) = Format(CInt(s(2)) + 1, "00") ElseIf CInt(s(2)) = 9 Then s(2) = Format(0, "00") s(1) = CInt(s(1)) + 1 s(1) = Format(CInt(s(1)), "00") End If If CInt(s(1)) = 10 Then s(0) = Format(CInt(s(0)) + 1, "00") s(1) = Format(0, "00") End If Label1.Text = s(0) & ":" & s(1) & ":" & s(2) End Sub Hope this solves the purpose.
LOL! This is awesome advice!!!
-
I just forgot to mention one thing. Declare an string array globally like: Dim s() as String Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' supposing we have a label and it has the text 00:00:00 when the form loads ' Timer interval we can set as per requirement ' I have set it for 0-9. If you want to test upto 1 minute then change 9 by 99 and 10 by 100 s = Label1.Text.Split(":") If CInt(s(2)) >= 0 AndAlso CInt(s(2)) < 9 Then s(2) = Format(CInt(s(2)) + 1, "00") ElseIf CInt(s(2)) = 9 Then s(2) = Format(0, "00") s(1) = CInt(s(1)) + 1 s(1) = Format(CInt(s(1)), "00") End If If CInt(s(1)) = 10 Then s(0) = Format(CInt(s(0)) + 1, "00") s(1) = Format(0, "00") End If Label1.Text = s(0) & ":" & s(1) & ":" & s(2) End Sub Hope this solves the purpose.
Wow, this is pretty bad. A value of time like this would normally be represented in your code by a TimeSpan object. You can then increment this time by adding 1 second to it on each tick of a 1000 millisecond timer. Your code can then be replaced by a very simple, single line of code:
Label1.Text = myTimeSpan.ToString()
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Wow, this is pretty bad. A value of time like this would normally be represented in your code by a TimeSpan object. You can then increment this time by adding 1 second to it on each tick of a 1000 millisecond timer. Your code can then be replaced by a very simple, single line of code:
Label1.Text = myTimeSpan.ToString()
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Dave Kreskowiak wrote:
Wow, this is pretty bad
Masterful understatement, such restraint.