?
Solved

Do Events

Posted on 2002-03-18
6
Medium Priority
?
181 Views
Last Modified: 2013-11-25
Hello Experts:

Just a simple question.  Can someone explain what the 'Do Events' syntax performs?  Haven't been able to find and info on this.

Thanks
0
Comment
Question by:zdpl0a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6878764
Is it DoEvents.. A command which let OS to handle other process/operation while you still processing. Sometime we use it to prevent the Interface from being 'hang'. Try to find more documentation on MSDN. Cheers
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6878818
Try F1 (HELP) while your cursor sits on "DoEvents" in a VB code window...
0
 
LVL 1

Accepted Solution

by:
RHuebner earned 20 total points
ID: 6878876
DoEvents command causes your process to yield to the next process in line. This command is used when you are using an out-of-process component (i.e. web browser) and are waiting for it to finish a command to prevent the preception that your program is hung and to keep two processes in sync.

Example 1 'Keeping processes in sync
ComponentA.LoadSomething          'Method of out of process
Do Until ComponentA.Ready = True 'Wait until component is ready
  DoEvents
Loop                             'Continue the Loop
ComponentA.DoSomething

Example 2 'Preventing the precention of being hung
For I = 1 to 1000000
 'Some commands
  DoEvents  'Allows user to do other things while waiting
Next

Hope this explains the command a little more. for the most part you shouldn't need to use it much.

Good Luck,
RH.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:mdougan
ID: 6879853
Well, like RHuebner says, the currently active code will have the priority when running, and DoEvents is a way to allow other activity to occure that would normally have to wait until the running code is finished.  But I disagree about the out-of-process stuff.  I'm sure it will affect out-of-process stuff, but it is more commonly used to give some processing time to in-process stuff.

One example, let's say that you have a progress bar on your screen and you have code that goes to the database, gets a few thousand records and then loop through the recordset putting them into a table.  At the bottom of the loop, you update the progress bar to show the percent complete.

It's possible that even though you updated the progress bar's value, the change wont show up on the screen because the processor is so busy inside of your loop, that it doesn't have time to process the Paint Event that was sent to the progress bar to repaint and show the progress.  That Paint Event is sitting in the Windows Event Queue.

Doevents puts the current code on hold long enough to clear out the Windows Event Queue.  As soon as the Windows Event Queue is empty, it will return control to your active code.

The only time DoEvents is dangerous is if you have some other background process that is continually filling up the Windows Event Queue. If so, then when you issue a DoEvents, you might not ever come back from that call!

So, to finish with the example, if you put a DoEvents after the instruction that updated the value for the Progress Bar, then it would probably have enough time to refresh the bar after every loop.

In general, if you have a processing loop that will go one for some time, it's a good idea to include one of these in the loop, however, it can slow down your processing.
0
 
LVL 1

Expert Comment

by:RHuebner
ID: 6884550
The out-of-process comment come from past experence with the web-browser component, when having to wait for the component to finish loading a page before doing something with the document displayed you would need to use doevents to get the web-browser control to finish loading otherwise you could end up with some strange errors.

I must agree you should seldom use the doevents command cause you have no control over when your process gets to run again.

RH.
0
 

Author Comment

by:zdpl0a
ID: 6897090
Thanks for the input from everyone and the examples.. Answered my question
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question