Continuous timer Help! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Continuous timer Help!

GanasGilerGanasGiler Posts: 2Member
I am new to VB and i have problem with my timer, I managed to run the timer until enddste 1.
How do I continue beyond that?

this is my code

Public Class Form1

Dim startdate As DateTime = DateTime.Parse(Date.Now)
Dim enddate As DateTime = DateTime.Parse("21:53:00")
Dim enddate1 As DateTime = DateTime.Parse("21:54:00")
Dim enddate2 As DateTime = DateTime.Parse("21:55:00")
Dim enddate3 As DateTime = DateTime.Parse("21:56:00")
Dim enddate4 As DateTime = DateTime.Parse("21:57:00")
Dim enddate5 As DateTime = DateTime.Parse("21:58:00")
Dim Flag As Boolean
Dim ts, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ts8, ts9, ts10, ts11, ts12 As TimeSpan
Dim ts13, ts14, ts15, ts16, ts17, ts18, ts19, ts20, ts21, ts22, ts23, constant As TimeSpan
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Enabled = True
ts = enddate.Subtract(startdate)
ts1 = enddate1.Subtract(enddate)
ts2 = enddate2.Subtract(enddate2)
ts3 = enddate3.Subtract(enddate3)
ts4 = enddate4.Subtract(enddate4)
ts5 = enddate5.Subtract(enddate5)
Flag = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ts = ts.Subtract(New TimeSpan(0, 0, 1)) '~~~ Subtract 1 second
ts2 = ts2.Subtract(New TimeSpan(0, 0, 1))
ts4 = ts4.Subtract(New TimeSpan(0, 0, 1))
'~~~ Display it
Label1.Text = CStr(ts.Hours) & " Hours: " & CStr(ts.Minutes) & " minuter: " & CStr(ts.Seconds) & " second"
'~~~ Check if the countdown is finished or not
If Math.Floor(ts.TotalSeconds) = 0 Then
If Flag = True Then
ts = ts1
Flag = False
ElseIf Flag = True Then
ts2 = ts3
Flag = False
ElseIf Flag = True Then
ts4 = ts5
Flag = False
End If
MessageBox.Show("Finished !")
End If
End Sub

End Class
Sign In or Register to comment.