hey guys.am working on a program. i have a timer and want it to countdown to zero when the button is clicked any ideas i'd appreciate.cheers.

Recommended Answers

All 2 Replies

Add this under "Public class Form1 ....":

Dim count As Integer = 100

Add a label to the form.

Add this to the Button_Click event code:

Timer1.Start()

Double-click the timer to add the Timer_Tick event and use this code:

count -= 1
Label1.Text = count

Thanks

Public Class Form1

    Dim Count As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Count = 10 ' Edit this value
        With Timer1
            .Interval = 1000 ' 1 sec
            .Enabled = True ' Start Timer
        End With
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Count -= 1 ' Same as Count = Count - 1
        Console.Write(Count) ' Write Output
        If Count <= 0 Then
            Timer1.Enabled = False ' Stop Timer
            '''''''''''''''''''''''''''''''''''''''''
            ''  D O   S O M E T H I N G   H E R E  ''
            ''    C O U N T D O W N   D O N E      ''
            '''''''''''''''''''''''''''''''''''''''''
        End If
    End Sub

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.