Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain DoEvent

Status
Not open for further replies.

Haheehi

Programmer
Sep 4, 2000
28
0
0
SG
Can any 1 explain the meaning of DoEvents [sig][/sig]
 
Yes
It allows your program to let the computers CPU look at the computer for a bit. This is done if you have a lot of intensive programming in your program.

I use it sometimes when I want a form to pop up and it won't.

form1.visible = true
doevents
' do some other processing

Also if it seems to skip something and you know its supposed to run that code put in a doevents statement.





[sig]<p>DougP, MCP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.[/sig]
 
I still dont really understand. [sig][/sig]
 
The DeEvent function yields execution to the operating system so it can process other events, The operating system then processes all of the events in its queue then returns control to the Subroutine or Function that called DoEvents.

One comman use for DoEvents is inside a large loop so as to allow the user to cancel the loop, other wise your program is frozen intill the loop is complete

Its not allways the best way to yield to the operating system from a Function/Sub especialy if that Function/Sub can get called from somewhere else in which case things get unpreditable, also dont use it if other processes interact with your procedure.

Also the DoEvent function will return an integer that represents the number of open forms in your program.

There are better ways to yield to the operating system then the DoEvents, but that is just my opion.

Collin [sig][/sig]
 
Eg. if you have a label on a form, and a loop that changes the caption of the label while it run,
and it don't changes caption when you run it, then add DoEvents and the caption will changes
as many times as you want while the loop is running... NeoAndresen
ComputerTech/Programmer
 
The best way I can explain this is. Let's say you have a Loop that runs constantly, because you want to show a clock or something else like that. But you want to be able to stop the Loop with the click of a button. If we programmed this way, your program would be frozen you would never be able to stop it.
[tt]
Do Until blExit = True
lblTime = Now()
Loop

Private Sub Command1_Click()
blExit = True
End Sub
[/tt]
Now if we wanted to stop this clock with the push of a button it would not work. The program would be busy doing the loop and it would never exit.

To be able to get the event of pressing the events we have to let the program release itself from the loop to process any other events waiting. So we would do this.
[tt]
Do Until blExit = True
lblTime = Now()
DoEvents
Loop

Private Sub Command1_Click()
blExit = True
End Sub
[/tt]
Try the code both ways and see what happens. BTW if your stuck in an infinite loop on the first way then Press CTRL+Break to stop the loop. Craig, mailto:sander@cogeco.ca

&quot;Procrastination is the art of keeping up with yesterday.&quot;

I hope my post was helpful!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top