Ok first of all when I was reading a thread on Timers before this guy posted code for a timer and its really good, but only problem with it which I cant figure out is that when I run the program the Msgbox("You have run out of time")..Which is from Line 15 to 25 of Code...If anyone can amend the code (because I cant think of how to do it) so it just works normally and doesnt come up with the message box staright away, I would appreciate it.. Thanks
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartStop.Click
If btnStartStop.Text = "Start" Then
CountDownTime = Now.AddMinutes(span)
Dim ts As TimeSpan = CountDownTime.Subtract(Now)
Min.Text = ts.Minutes.ToString
Sec.Text = ts.Seconds.ToString
Timer1.Start()
btnStartStop.Text = "Stop"
Else
Timer1.Stop()
btnStartStop.Text = "Start"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If CountDownTime < Now Then
Timer1.Stop()
MessageBox.Show("You have run out of time.")
btnStartStop.Text = "Start"
Else
Dim ts As TimeSpan = CountDownTime.Subtract(Now)
Min.Text = ts.Minutes.ToString
Sec.Text = ts.Seconds.ToString
End If
End Sub