Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When to use DoEvents

Status
Not open for further replies.

dc20

Technical User
Dec 15, 2003
95
US
I recently wrote a program that would hang at the end and not allow scrolling until I clicked outside the program. After much frustration, I stumbled on and tried the DoEvents command at the end of the program and that fixed it.

My question is, do you have tips or suggestions when it is appropriate to include this command ?
 
From MSDN

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.

Now to give an example:

Do until RS.eof = true
'Do something with the Record
do events
if boolCanceledClicked = true then
boolCanceledClicked = false
exit do
end if
loop


In this example you would place in the click event of a cancel button boolCanceledClicked = true. If you did not have the DoEvents it would finish the loop prior to firing that click event, but in this case the doevents says go out and check if there are any pending events.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top