Results 1 to 10 of 10

Thread: newbie ques.. Timers

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3

    newbie ques.. Timers

    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
    Last edited by helper; Aug 28th, 2002 at 06:39 PM.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.
    Last edited by Edneeis; Aug 28th, 2002 at 07:30 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3
    LMAO, oh man im dumb

    i fixed it

  4. #4
    Member
    Join Date
    Aug 2002
    Posts
    41
    lol..

    i would also like to know the answer for this

  5. #5
    Member
    Join Date
    Aug 2002
    Posts
    41
    anyone know how to do this?

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

    VB Code:
    1. Private btnLastClicked As System.Windows.Forms.Button
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         btnLastClicked = Button1
    5.         Timer1.Interval = 4000
    6.         Timer1.Stop()
    7.     End Sub
    8.  
    9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    10.         btnLastClicked = Button1
    11.         MessageBox.Show("Button 1 clicked")
    12.         Timer1.Start()
    13.     End Sub
    14.  
    15.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    16.         btnLastClicked = Button2
    17.         MessageBox.Show("Button 2 clicked")
    18.         Timer1.Start()
    19.     End Sub
    20.  
    21.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    22.         btnLastClicked = Button3
    23.         MessageBox.Show("Button 3 clicked")
    24.         Timer1.Start()
    25.     End Sub
    26.  
    27.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    28.         btnLastClicked = Button4
    29.         MessageBox.Show("Button 4 clicked")
    30.         Timer1.Start()
    31.     End Sub
    32.  
    33.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    34.         btnLastClicked = Button5
    35.         MessageBox.Show("Button 5 clicked")
    36.         Timer1.Start()
    37.     End Sub
    38.  
    39.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    40.         Timer1.Stop()
    41.  
    42.         If btnLastClicked Is Button1 Then
    43.             Button2_Click(sender, e)
    44.             Return
    45.         End If
    46.         If btnLastClicked Is Button2 Then
    47.             Button3_Click(sender, e)
    48.             Return
    49.         End If
    50.         If btnLastClicked Is Button3 Then
    51.             Button4_Click(sender, e)
    52.             Return
    53.         End If
    54.         If btnLastClicked Is Button4 Then
    55.             Button5_Click(sender, e)
    56.             Return
    57.         End If
    58.         If btnLastClicked Is Button5 Then
    59.             Button1_Click(sender, e)
    60.             Return
    61.         End If
    62.     End Sub
    63.  
    64.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    65.         Timer1.Stop()
    66.     End Sub

  7. #7
    Member
    Join Date
    Aug 2002
    Posts
    41

    Talking

    thanks for your help

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  9. #9
    Member
    Join Date
    Aug 2002
    Posts
    41
    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

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3
    same here
    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width