Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Wait" or "Delay" 1

Status
Not open for further replies.

oakleaf8

IS-IT--Management
May 16, 2002
57
US
I'm outputting two sets of data to a com port with one pushbutton. After sending data set one I want to pause or wait 3 seconds to send data set two. How do I pause the code for 3 seconds?

Thanks,
Mick
 
Have you looked at the Sleep API?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You can use the Sleep API function, but there's a danger involved. If the user does something in the UI while your Sleep function is idling, the window won't respond. For example, if they click a command button, it won't appear to sink, or if they click a form's minimize button, nothing will happen, until your sleep period expires. This can be confusing to the user.

At a minimum, you should be showing the hourglass cursor while your output code is running. Even better would be to show a "please wait" form or even a progress meter, along with the hourglass.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thank you, all! Both methods work fine, I opted to use DateDiff.
 
That's a good point RickSpr, You are completely correct that when using Sleep, the application will not respond to any events during the sleep interval.

But I wouldn't necessarily call that a danger of using the Sleep API. In fact, it may be quite desireable not have any user-interactions or other interruptions during the Sleep interval depending on what your program is doing during that interval. If for example, a second data set can be sent by the pressing of a button, then using sleep will prevent that button event from firing during the interval, whereas the DoEvents loop will not prevent the firing during the interval.

I'm glad that you brought it up, because one does need to know the ramifications of their choices, be it not having any user interaction during the sleep interval, or the performance implication of using a tight DoEvents loop. Both have their places, and as you pointed out, they are not interchangeable.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top