About Aaron Young Expertise I have 11 Years of Programming Experience, 4 years with Visual Basic, I currently work as an Analyst Programmer for Red Wing Business Systems, Inc. I enjoy helping others out when they get stuck and have spent a lot of time in other Forums like VB-World and CodeGuru answering a lot of questions. I have a good knowlegde of VB overall, so will attempt any Question on any part of the Language, from Database Access to ActiveX Control Creation and all the Grey Fuzzy stuff in between. (I do enjoy using the APIs for Subclassing and getting that last drop of functionality out of VB).
Expert: Aaron Young Date: 4/14/2005 Subject: The DoEvents Function
Question What is the DoEvents Function used fore
Answer Curt,
DoEvents is used to force the application to yield it's use of the processor for one cycle (usually 50ms), it's commonly used to allow other events in your application to fire while you're performing a resource intensive operation.
Here's an example, this code causes the Form's Caption to Count from 1 To 10,000 and also checks to see if you've decided to cancel it by clicking the "Cancel" button.
Run the code with the "DoEvents" line commented out first and you'll notice that you can't click the "Cancel" button to cancel the count. This is because the loop isn't allowing anything else in your application to use the processor.
Now run the same code again, but this time uncomment the "DoEvents" line, now you'll see that you can cancel the loop at any time without a problem.