Search code examples
processvb6

How do I delay code execution in Visual Basic (VB6)?


I have a long running process in VB6 that I want to finish before executing the next line of code. How can I do that? Built-in function? Can I control how long to wait?

Trivial example:

Call ExternalLongRunningProcess
Call DoOtherStuff

How do I delay 'DoOtherStuff'?


Solution

  • VB.Net: I would use a WaitOne event handle.

    VB 6.0: I've seen a DoEvents Loop.

    Do
         If isSomeCheckCondition() Then Exit Do
         DoEvents
    Loop
    

    Finally, You could just sleep:

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