Results 1 to 7 of 7

Thread: Timer Question

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Timer Question

    I'm trying to get my app to wait 60 seconds before moving on to the next set of code. I tryed the below but it doens't wait 60 seconds as it should. Can someone help me out.

    VB Code:
    1. Option Explicit
    2. Dim Counter As Integer
    3.  
    4. Private Sub Form_Load()
    5. Timer1.Interval = 10000
    6. Timer1.Enabled = True
    7. Counter = "0"
    8. Do Until Counter = 6
    9. Timer1_Timer
    10. Loop
    11.  
    12. MsgBox "60 seconds has passed"
    13. End Sub
    14.  
    15. Private Sub Timer1_Timer()
    16. Counter = Counter + 1
    17. End Sub

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Its the code in the Timer sub that will fire in the Timer Interval.

    Search for Sleep, that may work better for you.

  3. #3
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Option Explicit
    2. Dim Counter As Integer
    3.  
    4. Private Sub Form_Load()
    5. Timer1.Enabled = True
    6. Timer1.Interval = 10000
    7. Counter = "0"
    8.  
    9. End Sub
    10.  
    11. Private Sub Timer1_Timer()
    12. Counter = Counter + 1
    13. If Counter = 6 Then
    14.     MsgBox "60 seconds has passed"
    15.     Call MyNextSub
    16. End If
    17.  
    18. End Sub
    But here is a better way that doesn't use the Timer control.

    VB Code:
    1. Dim dblClock As Double
    2.    
    3.     dblClock = Timer
    4.     While Timer < dblClock + 60
    5.         DoEvents
    6.     Wend
    7.     MsgBox "60 seconds has passed"

  5. #5

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Thanks MartinLiss

  6. #6

  7. #7

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    don't worry, i won't start using your current avatar as well

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