Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
199 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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