• Log in or sign up for an account here: https://www.sythe.org/login

[BeginnerTut] Making a timer countdown

  • Thread starter Thread starter GordonBM
  • Start date Start date
G

GordonBM

Guest
[BeginnerTut] Making a timer countdown
Very simple.

Make a textbox, a button and two timers.
Set Timer1 interval to 60000 (or whatever you like, I use 60000 for this example) and set Timer2 interval to 1.
Now double click the button to open the code and fill this in:

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer2.Enabled = True
        Timer1.Enabled = True
    End Sub

Now go back to the design tab, double click the Timer2 and fill this in the code section:

Code:
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If Timer2.Enabled = True Then
            Timer1.Interval = Timer1.Interval - 1
            TextBox1.Text = Timer1.Interval
        End If
    End Sub

This means everytime Timer1 counts 1 down, Timer2 will be activated making the text of textbox1 update.

Full code:
Public Class Form1

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer2.Enabled = True
        Timer1.Enabled = True
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If Timer2.Enabled = True Then
            Timer1.Interval = Timer1.Interval - 1
            TextBox1.Text = Timer1.Interval
        End If
    End Sub
End Class

This was a VERY beginner tutorial.
Cheers.
 
Runescape Gamblingrunescape gambling
Back
Top