PDA

Click to See Complete Forum and Search --> : newbie ques.. Timers


helper
Aug 28th, 2002, 12:44 PM
i made 5 buttons
i want the 5th button, when clicked, to click on button 1, and after 5 seconds, click on button 2.. after 5 more sec to click on button 3, then after 5 more secs button 4

please show me the code
thanks

Edneeis
Aug 28th, 2002, 01:19 PM
Huh?

If you only have 3 buttons how can it click on button 4? Is this one of those tricky word math problems?

If you already have a timer somewhere then just set its interval to 5000 and in the tick event (Or whatever the event is called now) and then fire the click event of the right button in there.

helper
Aug 28th, 2002, 06:38 PM
LMAO, oh man im dumb :(

i fixed it

h3adbang3r
Aug 29th, 2002, 04:07 PM
lol..

i would also like to know the answer for this

h3adbang3r
Aug 31st, 2002, 05:10 PM
anyone know how to do this?

hellswraith
Aug 31st, 2002, 05:35 PM
Here you go, put 6 buttons on the form, and add a timer control. Map the click events to the buttons and the tick event to the timer.

The five buttons will be what you want clicked, and the sixth is just to stop the timer when you want it to stop clicking the next button every four seconds.


Private btnLastClicked As System.Windows.Forms.Button

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnLastClicked = Button1
Timer1.Interval = 4000
Timer1.Stop()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
btnLastClicked = Button1
MessageBox.Show("Button 1 clicked")
Timer1.Start()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
btnLastClicked = Button2
MessageBox.Show("Button 2 clicked")
Timer1.Start()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
btnLastClicked = Button3
MessageBox.Show("Button 3 clicked")
Timer1.Start()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
btnLastClicked = Button4
MessageBox.Show("Button 4 clicked")
Timer1.Start()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
btnLastClicked = Button5
MessageBox.Show("Button 5 clicked")
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()

If btnLastClicked Is Button1 Then
Button2_Click(sender, e)
Return
End If
If btnLastClicked Is Button2 Then
Button3_Click(sender, e)
Return
End If
If btnLastClicked Is Button3 Then
Button4_Click(sender, e)
Return
End If
If btnLastClicked Is Button4 Then
Button5_Click(sender, e)
Return
End If
If btnLastClicked Is Button5 Then
Button1_Click(sender, e)
Return
End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Timer1.Stop()
End Sub

h3adbang3r
Aug 31st, 2002, 09:56 PM
thanks for your help

hellswraith
Aug 31st, 2002, 11:19 PM
No problem. I am sure you could change the timer tick event code to reduce the if statements, maybe something like a select case statement.

h3adbang3r
Aug 31st, 2002, 11:23 PM
Originally posted by hellswraith
No problem. I am sure you could change the timer tick event code to reduce the if statements, maybe something like a select case statement.

yea, i just wanted to see how the timer works, cause i had no clue

now i do .. thanks to u

helper
Aug 31st, 2002, 11:24 PM
same here
thanks! :D