Look at your code:
Private Sub timerStandard_Tick(sender As Object, e As EventArgs) Handles timerStandard.Tick
If temp = 0 Then
MsgBox("Time is Over")
Else
temp = -1
SetTime()
End If
End Sub
Private Sub SetTime()
lblStandardHourValue.Text = temp / 3600
lblStandardMinValue.Text = (temp Mod 3600) / 60
lblStandardSecValue.Text = temp Mod 3600 Mod 60
If lblStandardHourValue.Text = 1 Then
lblStandardHourValue.Text = "0" & lblStandardHourValue.Text
End If
If lblStandardMinValue.Text = 1 Then
lblStandardMinValue.Text = "0" & lblStandardMinValue.Text
End If
If lblStandardSecValue.Text = 1 Then
cmbStandardSec.Text = "0" & cmbStandardSec.Text
End If
End Sub
SetTime
modifies the display from
temp
- but your tick event always sets
temp
to -1. So the value displayed will always be ... um ... garbage.
To do a countdown timer, the simplest way is:
Set up a Timer with an interval of half a second. Start it.
Set up a DateTime value: call it
expires
and set it to
DateTime.MinValue
.
In your Tick event, check if
expires
equals
DateTime.MinValue
.
If it does, do nothing.
If it doesn't, check it against DateTime.Now
If it's greater, use your
SetTime
method (modified) to display the difference (Hint: you can subtract two
DateTime
values to give you a
Timespan
which gives you hours, minutes, and seconds)
If it's smaller, the timer has elapsed, so set
expires
back to
DateTime.MinValue
.
Start and Stop operation for you app consist of setting the value of
expires
:
DateTime.MinValue
to stop it,
DateTime.Now.AddMinutes(30)
to wait half an hour.
Give it a try: it's a lot easier than it looks!