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:
  1. Private Const QS_HOTKEY = &H80
  2. Private Const QS_KEY = &H1
  3. Private Const QS_MOUSEBUTTON = &H4
  4. Private Const QS_MOUSEMOVE = &H2
  5. Private Const QS_PAINT = &H20
  6. Private Const QS_POSTMESSAGE = &H8
  7. Private Const QS_SENDMESSAGE = &H40
  8. Private Const QS_TIMER = &H10
  9. Private Const QS_ALLPOSTMESSAGE = &H100
  10. Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
  11. Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
  12. Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY)
  13. 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)
  14.  
  15. Private Declare Function GetQueueStatus Lib "user32" (ByVal fuFlags As Long) As Long
  16.  
  17. Private Sub Command1_Click()
  18.     'start the loop
  19.     Do
  20.         'check whether there are mouse-button or keyboard messages
  21.         'in the message queue. If there are, call DoEvents
  22.         If GetQueueStatus(QS_ALLINPUT) Then DoEvents
  23.  
  24.     Loop Until bCancel = True
  25.  
  26. End Sub