ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DoEvent (https://www.excelbanter.com/excel-programming/302091-doevent.html)

Billabong

DoEvent
 
I am a neophyte programmer, I heard DoEvents can be used to run tw
sequence at almost the same time. But I dont know how to use it.
Anyone kind enough to show me how it works? A sample coding will do an
a bit expanation how it works.

Thanks

--
Message posted from http://www.ExcelForum.com


Dick Kusleika[_3_]

DoEvent
 
Billabong

DoEvents releases the processor from the currently executing macro for
whatever is in the processors queue. You normally should not need it, but
there are times when you do. Here's an example: Suppose you have a macro
that increments the value of a cell until the user hits a button. You might
set that up like this

Public bStop As Boolean

Sub IncrementCell()

Do
Range("A1").Value = Range("A1").Value + 1
DoEvents
Loop Until bStop

End Sub

Sub StopIncrement()
'assigned to button

bStop = True

End Sub

If you didn't have the DoEvents in the first sub, the button would never be
available for the user to hit because the IncrementCell would never release
any processor time to anything else. Clicking the button to StopIncrement
will not do anything because StopIncrement will be in the processor's queue
waiting for IncrementCell to finish, which of course it never would.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Billabong " wrote in message
...
I am a neophyte programmer, I heard DoEvents can be used to run two
sequence at almost the same time. But I dont know how to use it.
Anyone kind enough to show me how it works? A sample coding will do and
a bit expanation how it works.

Thanks.


---
Message posted from http://www.ExcelForum.com/




Tom Ogilvy

DoEvent
 
Excel isn't multitasking and won't run two procedures at the same time.


as far as DoEvents, it is explained pretty well in Help:

"Yields execution so that the operating system can process other events."
If that is what you mean by two sequence then it can do that, but the second
sequence, the operating system tasks, are outside your control.

for i = 1 to 1000
doevents
' other actions
Next

might be useful if the code were making visible changes and they were not
being updated on the screen because the code is in a tight loop. Doevents
is usually used primarily when problems are encountered.

--
Regards,
Tom Ogilvy



"Billabong " wrote in message
...
I am a neophyte programmer, I heard DoEvents can be used to run two
sequence at almost the same time. But I dont know how to use it.
Anyone kind enough to show me how it works? A sample coding will do and
a bit expanation how it works.

Thanks.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com