about timertick

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
halu i'll make a stop watch
here's the code
VB.NET:
 dim startime as datetime 
Private Sub timertick_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timertick.Tick 
		Dim span As TimeSpan = Date.Now.Subtract(startime) 
		Label1.Text = span.Hours.ToString & " : " & span.Minutes.ToString & " : " & span.Seconds.ToString & " . " & span.Milliseconds 
	End Sub 
in the button1_click 
 
	   If timertick.Enabled Then 
			timertick.Stop() 
			button1.Text = "click to start" 
		Else 
			startime = Date.Now() 
			timertick.Start() 
			button1.Text = "click to stop"      
		End If
when i click stop the clock will stop...what i want is when i click start it will continue to where the time stop..

for example: it will stop at 2.704 and when i click start it will continue like..2.705 up...

i hope it explains well.
tanx in advance and more power...;)
 

Jonatan

Member
Joined
Jun 8, 2004
Messages
11
Location
Cuba
Programming Experience
3-5
timertick fixed

Hi! Maybe this answer could serve you. I just modified a few lines of your previous code...
Dim startime As DateTime

Dim span, prevspan As TimeSpan, totalspan As New TimeSpan(0, 0, 0, 0, 0)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If TimerTick.Enabled Then

TimerTick.Stop()

prevspan = totalspan

Button1.Text =
"click to start"

Else

startime = Date.Now

TimerTick.Start()

Button1.Text =
"click to stop"

End If

End Sub

Private Sub TimerTick_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TimerTick.Tick

span =
Date.Now.Subtract(startime)

totalspan = prevspan

totalspan = totalspan.Add(span)

Label1.Text = totalspan.Hours.ToString &
" : " & totalspan.Minutes.ToString & " : " & totalspan.Seconds.ToString & " . " & totalspan.Milliseconds

End Sub

 
Top Bottom