DoEvents (statement)

Syntax DoEvents
Description Yields control to other applications.
Comments This statement yields control to the operating system, allowing other applications to process mouse, keyboard, and other messages. If a SendKeys statement is active, this statement waits until all the keys in the queue have been processed.
Examples This first example shows a script that takes a long time and hogs the system. The following routine explicitly yields to allow other applications to execute and refresh on a regular basis.
Sub Main()
  Open "test.txt" For Output As #1
  For i = 1 To 10000
    Print #1,"This is a test of the system and stuff."
    DoEvents
  Next i
  Close #1
End Sub
In this second example, the DoEvents statement is used to wait until the queue has been completely flushed.
Sub Main()
  id = Shell("notepad.exe",3)  'Start new instance of Notepad.
  SendKeys "This is a test.",False 'Send some keys.
  oEvents                   'Wait for the keys to play back.
End Sub
See Also DoEvents (statement).