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?
LVL 31
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Surone1Commented:
try using a timer instead? sleep() will lock up your app and make user interaction nearly impossible. a timer would not.
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
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?
0
Surone1Commented:
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
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Surone1Commented:
For i = 1 To 100
Sleep (150)
DoEvents
Next i
0
Martin LissOlder than dirtCommented:
All you need to do is to put a Timer control on the form and then add this code.


Option Explicit

Private Sub Form_Load()
Timer1.Interval = 900000 ' 15 minutes in milliseconds
Timer1.Enabled = True

End Sub


Private Sub Timer1_Timer()
MsgBox "Do your update here"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
Excellent suggestions everyone. Unfortunately I probably won't get back to this today but when I do I'll return and award points.
0
Martin LissOlder than dirtCommented:
Have you returned?
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
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).
0
Martin LissOlder than dirtCommented:
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.
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperAuthor Commented:
My fault for not closing this... will do so now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.