I am trying to put a countdown timer insde my label in my program, but when I run the program it doesn't countdown. It skips right to one, and that's it.
Private Sub CompactTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompactTimer.Tick
Dim Time As Integer = 11
Do Until Time = 0
ClockLabel.Text = "Compacting database in: " & Time
Time -= 1
Loop
End Sub
I also have started the timer and declared the interval to 500 in the Form_Load routuine.
Get rid of the loop and declare the Time variable outside the scope.
Dim Time As Integer = 11
Private Sub CompactTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) _
Handles CompactTimer.Tick
If Time >= 0 Then
ClockLabel.Text = "Compacting database in: " & Time
Time -= 1
Else
CompactTimer.Stop
End If
End Sub
make a static var ..
Private Sub CompactTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompactTimer.Tick
Static Time As Integer = 11
ClockLabel.Text = "Compacting database in: " & Time
Time -= 1
If Time = 0 Then CompactTimer.Stop
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With