Re: DoEvents

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dick Grier (dick_grierNOSPAM_at_msn.com)
Date: 05/05/04


Date: Wed, 5 May 2004 08:36:57 -0600

Hi,

DoEvents may or may not be required. If there are lots of them scattered
around, I suspect that some are spurious, and may cause trouble. However,
some may be needed. Often they might be replaced by a call to me.Refresh
(or some control.Refresh).

If your code is in a long loop, DoEvents allows the program to process
events that will execute other code. However, this may cause some routine
to be re-entered (perhaps the one that is in the long loop), when logic
dictates that it should not. In this case, you need to have a state (flag)
that you check to determine if the code should be re-entered. Remember to
reset the flag when the loop finally exits. If the event that is causing
the trouble is associated with a button click event, then you can simply
change the Enabled property to False prior to executing the loop, and
resetting the Enable property to True when the loop exits.

Solving this sort of problem will take some detailed analysis of the actual
code. Anything that we say on the subject is mere speculation.

***

-- 
Richard Grier  (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.

Quantcast