Description
Yields execution so that the operating system can process other events.
Syntax
DoEvents
Remarks
DoEvents passes control to the operating system. Control is not returned until the operating system has finished processing the events in its queue and, for Microsoft Windows only, all keys in the SendKeys queue have been sent.
If parts of your code take up too much processor time, use DoEvents periodically to relinquish control to the operating system so that events, such as keyboard input and mouse clicks, can be processed without significant delay.
Caution
Make sure the procedure that has given up control with DoEvents is not executed again from a different part of your code before the first DoEvents call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.
Example
This example uses the DoEvents Statement to cause execution to yield to the operating system once every 1000 iterations of the loop.
For I = 1 To 150000 ' Start loop. If I Mod 1000 = 0 Then ' If loop has repeated 1000 times. DoEvents ' Yield to operating system. End If Next I ' Increment loop counter.