Results 1 to 8 of 8

Thread: Timer

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    13

    Timer

    Im trying to put a delay between the button click and the message box that pops up. Here is my code, please help me out with this.

    Private Sub TimerFire()
    Me.Timer1.Interval = 3000
    Me.Timer1.Enabled = True
    End Sub

    Private Sub TimerStop()
    Me.Timer1.Enabled = False
    End Sub

    Private Overloads Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TimerFire()
    MsgBox("ok")
    End Sub
    Crystal Reports beheaded!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Timer

    try this
    [code]
    Private Sub TimerFire()
    Me.Timer1.Interval = 3000
    Me.Timer1.Enabled = True
    MsgBox("ok")
    Me.Timer1.Enabled = False
    End Sub


    Private Overloads Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TimerFire()
    [/Highlight]

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    13

    Timer

    Still does not work. There is no delay I cut and pasted the aforementioned code which looks like this now:

    Private Sub TimerFire()
    Me.Timer1.Interval = 3000
    Me.Timer1.Enabled = True
    MsgBox("ok")
    Me.Timer1.Enabled = False
    End Sub

    Private Overloads Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TimerFire()
    End Sub
    Crystal Reports beheaded!

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Timer

    Sorry , I mean this way !
    VB Code:
    1. Private Sub TimerFire()
    2.         Me.Timer1.Interval = 3000
    3.         Me.Timer1.Enabled = True
    4.     End Sub
    5.  
    6.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7.         TimerFire()
    8.     End Sub
    9.  
    10.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    11.         MsgBox("ok")
    12.     End Sub

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Re: Timer

    stop your timer when you're done !

    VB Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2. MsgBox("ok")
    3. Me.Timer1.Enabled = False
    4. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    13

    Timer

    Thank you for your time. I really appreciate it. Heres another easier (my pov) delay method that I found elsewhere on this forum:

    Private Declare Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)

    Private Overloads Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Sleep(1250)
    MsgBox ("ok")
    End Sub
    Crystal Reports beheaded!

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Timer

    No problem .... You can do something alike with threadings . It has sleep , pause , resume methods .

  8. #8
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         'Sleep for 3 seconds
    4.         Threading.Thread.Sleep(3000)
    5.  
    6.         'Show MessageBox
    7.         MessageBox.Show("Ok!")
    8. End Sub


    simple code, makes the thread the code is running in pause for 3 seconds.. which would make your program pause before showing a message box

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