Monday, July 2, 2007

Delaying a Visual Basic Program

Here is a very useful means of creating a known delay in VB 6.0. in case you need to wait on a different external process to finish. I recently needed a delay that was independent of CPU clock speed. This does the trick nicely. VB doesn't have a delay or wait function like most of the other basic languages it seems.

Copy this code into the declarations section of the project.

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



To delay the program for 1 second, use this code:

Call Sleep(1000)

No comments: