# VB and Sleep



## bear (Jan 1, 1999)

Hello,
I remember in the older versions of Quickbasic and Basic A, there was a sleep command that could be used to stop the program for a few seconds. I used that command after the processing was done and I wanted to screen to pause for a few seconds after the graphical changes were made.
Is there a simular command in VB 6 that I can use?? I have a graphical form that after it updates, it will show for a few seconds after the changes have been made, then hide.

Thanks,

bear


----------



## Rollin_Again (Sep 4, 2003)

At the top of the module


```
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
```
Then call it with a line such as


```
Sleep 5000
```
This will call the sleep command for 5 seconds

Regards,
Rollin


----------



## dquigley (Apr 17, 2006)

One problem with just using Sleep() on the UI thread in VB6 is that window messages do not get processed during the sleep interval. To solve this you can write your own "wait" function and use the DoEvents API. It's not as accurate as Sleep(), but it also doesn't "freeze" the UI.

Best,
Dan


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

Private Sub SleepWait(ByVal inMillisec As Long) 
    Dim TimerLoop As Long 

    ' Sleep for 100ms at a time 
    Const WaitInc = 100 

    Do 
        DoEvents 
        Sleep WaitInc 
        TimerLoop = TimerLoop + WaitInc 
    Loop While TimerLoop < inMillisec 
End Sub
```


----------



## bear (Jan 1, 1999)

Rollin & Dan,

Thanks for your replys!! I really appreciate all the help. I assume that a timer component needs to be on the form, correct???

bear


----------



## dquigley (Apr 17, 2006)

There is no dependancy on a timer control. I've used code like this in loops that take time to process - like gathering results sets from databases. 

Dan


----------



## bear (Jan 1, 1999)

Ok.....Thanks Dan.

Bear


----------

