I think it's a good idea to use DoEvents only when it's needed, which is why I use the GetQueueStatus() API function.
All it requires is to paste some API declarations/constants in your program and then a simple if/then statement in your loop.
This will make loops execute a lot faster and utilize a lot less CPU.
Here's some code from allapi.net
VB Code:
Private Const QS_HOTKEY = &H80 Private Const QS_KEY = &H1 Private Const QS_MOUSEBUTTON = &H4 Private Const QS_MOUSEMOVE = &H2 Private Const QS_PAINT = &H20 Private Const QS_POSTMESSAGE = &H8 Private Const QS_SENDMESSAGE = &H40 Private Const QS_TIMER = &H10 Private Const QS_ALLPOSTMESSAGE = &H100 Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON) Private Const QS_INPUT = (QS_MOUSE Or QS_KEY) Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY) Private Const QS_ALLINPUT = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY) Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long) As Long Private Sub Command1_Click() 'start the loop Do 'check whether there are mouse-button or keyboard messages 'in the message queue. If there are, call DoEvents If GetQueueStatus(QS_ALLINPUT) Then DoEvents Loop Until bCancel = True End Sub




Reply With Quote