Link to home
Start Free TrialLog in
Avatar of Scott Helmers
Scott HelmersFlag for United States of America

asked on

VB userform plus sleep() delay

I’m working on an application with three goals:
1.      Present a status screen to user that is updated every 15 minutes.
2.      Write data to Excel log file at each 15 minute interval.
3.      Alllow user to click a button on the status form to refresh it at any time, independent of the 15 minute timer.

I’m using the Windows sleep() function to implement the 15 minute wait, and at this point I have a VB6 application that accomplishes the first two goals with no problem. However, I can’t do #3. If I show the userform modally, the app pauses when the form is displayed, which means that the sleep function is never called. On the other hand, if I show the userform modelessly, the sleep timer runs but the buttons on the userform are inoperable.

I suspect I'm missing a fairly simple technique...

I happen to have written the app in VB6 for unimportant historical reasons… can I do this sort of multithreading in VB6? Or do I need to move to .Net or something else?
Avatar of Surone1
Surone1
Flag of Suriname image

try using a timer instead? sleep() will lock up your app and make user interaction nearly impossible. a timer would not.
Avatar of Scott Helmers

ASKER

I was trying to keep CPU cycles to the minimum, which sleep does reasonably well, but I'll try your suggestion. Any recommendations for minimum CPU usage timer code?
if you insist on using sleep:

try :

Sleep (1000)
DoEvents

Sleep (1000)
DoEvents

Sleep (1000)
DoEvents

Sleep (1000)
DoEvents

Sleep (1000)
DoEvents

Sleep (1000)
DoEvents


it will free up the app to handle user events every second
SOLUTION
Avatar of Surone1
Surone1
Flag of Suriname image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent suggestions everyone. Unfortunately I probably won't get back to this today but when I do I'll return and award points.
Have you returned?
My apologies to everyone who offered suggestions. I've been out of town with a family medical emergency -- still am in fact -- so I have not been near the system on which I can test the potential solutions.

Never fear, I will return and will accept the appropriate answer(s).
I've requested that this question be closed as follows:

Accepted answer: 250 points for Surone1's comment #a39547320
Assisted answer: 250 points for MartinLiss's comment #a39547481

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
My fault for not closing this... will do so now.