Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Is there a way to easily make a timer wait in the middle of code without usnig the sleep function.

Is there a way to easily make a timer wait in the middle of code without usnig the sleep function which locks up the whole system.
0
sentry360
Asked:
sentry360
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sure...

Private Sub Command1_Click()
    Dim targetTime As Date
   
    Debug.Print "delaying..."
    targetTime = DateAdd("s", 5, Now()) ' five seconds from now...
    While Now < targetTime ' wait until current time reaches targetTime
        DoEvents
    Wend
    Debug.Print "code delayed and continued!"
End Sub

The downside to this is the CPU usage goes up to 100%.  The application (and others) will remain responsive however.

Idle_Mind
0
 
sentry360Author Commented:
not quite as easy as I woud have wished, but thanks
0
 
GrahamSkanRetiredCommented:
The Timer control does not use the sleep function.

Add a Timer control and at the appropriate point and set its Interval to to your requirements. At the point that you want to wait, enable the timer and finish your procedure here.

Put the remainder of your code the Timer's Timer event.
0
 
GrahamSkanRetiredCommented:
Cross-posted, but note that the Timer control does not hang the system.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now