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.

8 Years
Discussion Span
Last Post by L0u3

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:


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

count -= 1
Label1.Text = count


Edited by farooqaaa: n/a

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.