Question

What are the benefits to using DoEvents over Repaint on a userform in VBA? Is it due to performance, for minimising the annoyance of things such as screen flicker, or for when you need to update more than just the form?

Looking for some clarification on the difference from a VBA perspective.

Was it helpful?

Solution

In general, VB6 and VBA uses DoEvents to tell the processor to continue processing the messages in the message queue. It is used when an intensive processing operation is being done in the processor and so the UI of the program is still responsive to all other events.

Example: You are doing an intensive search algorithm, if you didn't add DoEvents the program may hang up till it finishes the search. On the other hand, if you add DoEvents (to the search loop let's say) the program does not hang up and still can handle all program events like (Cancel) canceling the search.

EDIT: I see it as DoEvents is more comprehensive than Repaint since it deals with all event types not only handling the flicker/Hangup of the UI.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top