[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • 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
 
GrahamSkanCommented:
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
 
GrahamSkanCommented:
Cross-posted, but note that the Timer control does not hang the system.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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