Hey everyone,

I'm just playing with some code and timers seem to just confuse me :\.

Well what i want is a timer that counts down from 10 seconds and when it hits 0 it simply pops up a message box..

This is what i have so far.. not so spectacular..

Timer2.Interval = 10000 
        Timer2.Enabled = True
If Timer2.Enabled = False then
        msgbox("blah!")
End If

I'v tried a lot of different scenarios and i can't find one that does such a simple task...

Thanks in advance,
-Zander

Recommended Answers

All 3 Replies

The problem you are running into is that the timer is never set to Enabled=False

After the interval, the time does not become disabled, but rather, runs the code in its block again.

Try something like this:

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

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MsgBox("blah!")
        Timer1.Enabled = False
    End Sub

Once you understand what's going on here, you can look into making the timer more precise (i.e. the counter is meant to display the msgbox after 10 secounds; however, it may seem to be off by a little bit)

create a timer
set the interval
enable it
every time it ticks (timer.tick event) have some code to add 1 to a variable
have an if statement so it pops up an msgbox when the variable = 10

Timothy that worked perfectly!
Thanks!

-Zander

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.