Yields execution so that the operating system can process other events.
n = DoEvents()
n : ivar
DoEvents switches control to the operating-environment kernel. Control returns to your application as soon as all other applications in the environment have had a chance to respond to pending events. This doesn't cause the current application to give up the focus, but it does enable background events to be processed.
This function is extremely useful for programs that are constantly performing operations rather than waiting for user input for refreshing output to a specific window which Windows would otherwise report as being 'Non-Responsive' until the operations stopped for user input and a Sleep command was reached.
The DoEvents function returns (also when no message is pending) the number of the received messages.
By using DoEvents instead of Sleep, all simultaneous running programs (also server activities, printer spooler, etc.) will slow down. A loop with DoEvents prevents energy saving of a notebook. DoEvents was created only to use during long arithmetical calculation operations. The main message loop shouldn't use DoEvents, but instead use Sleep.
OpenW 1
Local n%
n = DoEvents()
Print n // Prints 1
Do : Sleep : Until Me Is Nothing
The essential difference between PeekEvent, which reads only one message a time and DoEvents, which handles all pending messages, is that PeekEvent stores all messages in the Menu() array and DoEvents only partially. Sleep doesn't use the Menu() array at all.
GetEvent and Sleep are more alike. Both wait for a message before going on. Sleep handles all pending messages, where GetEvent only handles one message.
When porting a GFA-BASIC 16 program you shouldn't use DoEvents or Sleep, but GetEvent or PeekEvent. By using GetEvent or PeekEvent you can get problems, if you use Ocx controls in your program.
As a rule: Don’t mix the Menu() array handling and Ocx controls. Use GetEvent/PeekEvent only in programs, that use the Menu() array. A program that uses OCXs has to use Sleep (and DoEvents).
OpenW 1
Do
Plot Rand(_X), Rand(_Y), Rand(_C)
DoEvents
// to see the difference with DoEvents
// remove the comment before Sleep
'Sleep
Until Me Is Nothing
Never use an empty loop like the following one
Do
DoEvents
Until Me Is Nothing
{Created by Sjouke Hamstra; Last updated: 03/10/2014 by James Gaite}