Scott Helmers
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?
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?
try using a timer instead? sleep() will lock up your app and make user interaction nearly impossible. a timer would not.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
ASKER
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).
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.
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.
ASKER
My fault for not closing this... will do so now.