Solved

Do Events

Posted on 2002-03-18
6
174 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
6 Comments
 
LVL 49

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now