Solved

Do Events

Posted on 2002-03-18
6
178 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 51

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 5 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 65
Run code from text file in vb 1 86
how to know if my Checkbox is True in VB6.0? 9 65
Error with a code discussed on this page 5 38
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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