Countdown Timer in VB.NET

Izzysabir

New member
Joined
Jun 6, 2005
Messages
3
Programming Experience
Beginner
Does anyone know how to set up a countdown timer in VB net?? i need it to expire in 360 days. A colleague of mine is retiring and would like it on his desktop as a countdown to the bigday. :eek:)
 
Last edited by a moderator:

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Hi,

First off, welcome to the forum. I hope you'll have nice time here at the vbdornetforums :)

Well, i attached an example/demo below so you can take a look at ...
btw, replace current values with commented ones ... you'll find sense i'm sure.

Happy coding ;)
 

Attachments

  • Countdown.zip
    22.5 KB · Views: 254

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Here's for the people that don't want to download a zip file, unzip it, then start VS just to get 17 lines of code:

You'll need a form with a Label named Label1 and a System.Windows.Forms.Timer named Timer1
VB.NET:
'just don't forget to replace comments with present values

    Private cdTime As Integer = 10 '360
    Private cdDay As Integer = 4 '86400

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        cdDay -= 1
        Label1.Text = cdTime & " days remaining"
        If cdDay <= 0 Then
            cdTime -= 1
            cdDay = 4 '86400
        End If
        If cdTime <= 0 Then
            Timer1.Dispose()
            Label1.Text = "360 days have been passed"
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = String.Empty
    End Sub
 
Top Bottom