The information in this article applies to:
SUMMARYThe DoEvents function surrenders execution of the macro so that the operating system can process other events. The DoEvents function passes control from the application to the operating system. Some instances in which DoEvents may be useful include the following:
MORE INFORMATIONHardware I/OIf your code waits for an input from any I/O device, the DoEvents function speeds up the application by multitasking. As a result, the computer does not seems to pause or stop responding (hang) while the code is executing.Example:
Delay LoopsIn a delay loop, the DoEvents function can allow the CPU operating system to continue with any pending jobs.Example:
Operating System CallsWhen Visual Basic calls the operating system, the operating system may return the control even before processing the command completely. Doing so may prevent any macro code that depends on an object generated by the call from running. In the example below, the Shell function starts the Microsoft Word application. If Word is not yet open, any effort to establish a DDE link to it will halt the code. By using DoEvents, your procedure makes sure that an operation, such as Shell, is completely executed before the next macro statement is processed.Example:
DDE DeadlockingConsider a situation in which a Visual Basic macro calls an application that is waiting for a second application to get some data. If the macro does not give control to the second application, the result is a deadlock. In DDE conversations between multiple applications, using DoEvents removes the possibility of this type of deadlocking.Problems Associated with DoEvents
REFERENCESFor more information about DoEvents, click the Search button in Help and type: doevents Additional query words: Sendkeys keystroke Wait XL98 XL97 XL7 XL5
Keywords : |
Last Reviewed: November 3, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |