VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Continuous timer Help! Posted by GanasGiler on 12 Dec 2012 at 6:24 AM
HI,
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
Timer1.Start()
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
Timer1.Stop()
If Flag = True Then
ts = ts1
Flag = False
Timer1.Start()
ElseIf Flag = True Then
ts2 = ts3
Flag = False
Timer1.Start()
ElseIf Flag = True Then
ts4 = ts5
Flag = False
Timer1.Start()
End If
MessageBox.Show("Finished !")
End If
End Sub

End Class
Thread Tree
GanasGiler Continuous timer Help! on 12 Dec 2012 at 6:24 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.