PDA

View Full Version : Solved: Is DoEvents really that slow



philfer
11-10-2008, 07:35 AM
I have this test code for DoEvents

Private Sub CommandButton1_Click()

Dim lngIndex As Long

For lngIndex = 1 To 9999
Label1.Caption = lngIndex
Next
Label1.Caption = "Done"

End Sub
Private Sub CommandButton2_Click()
Dim lngIndex As Long

For lngIndex = 1 To 9999
Label1.Caption = lngIndex
DoEvents
Next
Label1.Caption = "Done"


End Sub


And the version with DoEvents takes about twice as long to run

Does it really slow it down that much?

Why is that? Is it because it keeps passing control back to the op sys and taking it back

If so, whats really the point of using DoEvents as you are just making your macro slow, n'est pas?

Thanks
Phil

Bob Phillips
11-10-2008, 08:03 AM
As it says in Help

DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.

As such, it is bound to be slower elapsed, as it allows other tasks a lookin. But, it may be necessary for that same reason, and should only be used where needed.