Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
206 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
[X]
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
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

609 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