Pause for 5 seconds

In a vb5 script, I have a loop.  I want to have it pause for 5 seconds every time it iterates.
while (i <= 100) {
# do some stuff
# pause 5 seconds
)
What code would I put in to cause the pause?
donb1Asked:
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.

deightonprogCommented:
in a  .bas

Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

then
sleep(5000)   '5000 millisecs = 5secs


0
VBGuruCommented:
do you have timer function availble for you?

Then you can do like this?

dim l as long
l = timer + 60*5
while l > timer
wend
0
MaximkaCommented:
dim vTimer as  Variant

vTimer=Timer
do While True
    If Timer - vTimer > 5 then
       exit do
    end if
loop

Hope that will helps You .
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

lutharCommented:
Dim timedone As Single

Do While i <= 100
'instruction goes here

'Pause sequence here
      Let timedone = Timer
      Do While Timer < timedone + 5
      Loop
'Pause sequence finish
      i = i + 1
Loop

This should work ....
0
VbmasterCommented:
The best solution is to combine the do..loop with the Sleep API and add a DoEvents inside the do..loop block, something like this..

vTimer=Timer
Do Until (Time - vTimer > 5)
  DoEvents
  Sleep(100)
Loop

Because if you do a do..loop or a Sleep API only the application will freeze those five seconds and that will look like ****. The solution above will not freeze the redraw of the program AND will take less CPU time than the other solutions.

But this solution might not be applicable to your application because the DoEvents statement will make the program able to click on buttons on your program when the app is running the do..loop.
0
donb1Author Commented:
Maximka's comment works, the others don't work for me. At least it is the simplest solution for me.  Suggest Maximka make yours an answer.  Thanks also to the others for their interest.
0
VbmasterCommented:
The problem with my code was a

   vTimer=Timer
   Do Until (Timer - vTimer > 5)       '<- I missed a 'r' here
      DoEvents
      Sleep(100)
   Loop
0
paul_tsekovCommented:
Hi VBfan,

try the Timer function:
while (i <= 100) {
Dim Start,PauseTime
PauseTime = 5
# do some stuff
# pause 5 seconds
.....
.....
Start = Timer      ' Set start time.
Do While Timer < Start +PauseTime
Loop
            

This should organize an Active delay(
An empty cycle delaying for 5 seconds)


               Pavel Tsekov
         email : paul_tsekov@yahoo.com
0
VbmasterCommented:
Paul tsekov: start a program that monitors your CPU usage and see what happens when that code is run. ;)
0
donb1Author Commented:
Maximka's answer should get the credit
0
mcriderCommented:
So select Maximka's comment as the answer...  There is a link to do this on the right side of the green comment line for that entry.

Cheers!
0
sdland1Commented:
please visit http://lightning.prohosting.com/~shell123 and search the sniplets section for pause youll see about 20 examples
0
deightonprogCommented:
Are your using VB4 16 bit or lower or something?
0
donb1Author Commented:
When I used:
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
vb5 said I couldn't do that.
0
VbmasterCommented:
Where did you put that line? If you put it inside a class or form you will need to put the 'Private' keyword in front of it. Change the line to..

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
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.