Solved

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

Posted on 2004-08-23
4
192 Views
Last Modified: 2013-12-25
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
Comment
Question by:sentry360
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 11875942
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
 

Author Comment

by:sentry360
ID: 11875961
not quite as easy as I woud have wished, but thanks
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11875970
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11875990
Cross-posted, but note that the Timer control does not hang the system.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now