Link to home
Start Free TrialLog in
Avatar of DaveNoviceVB
DaveNoviceVB

asked on

Pause in VB for random duration

Hello again,

help - pleeeaaasssse!
How do I pause an application in VB for a random number of seconds - is there a sleep function or something available?

What I want to do is display a picture - then pause a random time between 2-5 seconds - then display another picture.

If you can answer this I would be most greatful.
Thanks,
Dave from Scotland
Avatar of hes
hes
Flag of United States of America image

Use the sleep api

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const ConvToMilli = 60000 ' convert to milliseconds

to use for 2 seconds

Sleep(ConvToMilli * 2)
For your random part

Dim MyPause
Randomize   ' Initialize random-number generator.

MyPause = Int((5 * Rnd) + 2)   ' Generate random value between 2 and 5.

Sleep(ConvToMilli * MyPause)

Hi, DaveNoviceVB !

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

Call Sleep(CLng(Int(3001 * Rnd) + 2000))
Avatar of gkollar
gkollar

Hello
I don't no if the Sleep win32 function freez the process. If no then the uper solution are good
if yes you must use a loop with a doevent instruction who re-give the hand to the system for other processus.

by example:
function sleep( iValue as integer)
dim first as variant
   first = now()
   do
      if (now()-first) > iValue then exit do
      doevent    
   while(true)

end function

best regard from france
Hi DaveNoviceVB,

You can try to use Timer Control also..

regards.
ASKER CERTIFIED SOLUTION
Avatar of murray_c
murray_c

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
If this proposed answer has helped you, please accept it, grade it and close this question.  If it did not, reject it and add comments as to your progress and what else is needed.  If no action is taken here by next week, we'll need to decide this outcome.  Expert input always welcome as well.

Thanks,
Moondancer
Community Support Moderator @ Experts Exchange
Thank you for returning and finalizing this.  It is requested that anytime you choose a grade less than "A" you add a comment as to why.  If the "B" was a default posed to you, please let me know that as well, so I can refer to Engineering.

If this was in error, let me know that as well so I can change it to an A, since it does not impact the points you pay, but indeed impacts the Expert Points received, which are determined by the grade assigned.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange