Visual Basic Tip: 12/18/95

Useful short tips: Wait, even/odd, menu, timeGetTime, DoEvents.
* Wait 5 seconds.  Note: Will not wait full 5 seconds when the 5 second
  range contains midnight.

   x! = Timer
   Loop While Abs(Timer - x!) < = 5

* Toggle between even and odd numbers.

   If i% And 1 Then
   End If

* Right justify top level menu item.

   Add a Chr$(8) to the beginning of the menu caption.

   mnuTopHelp.Caption = Chr$(8) & mnuTopHelp.Caption

* Use a timer that has greater resolution (generally 1 millisecond).
  Some of the other timers have values down to 1 millisecond, but you
  can't get the precise 1 millisecond resolution.

   Declare Function timeGetTime Lib "MMSYSTEM" () As Long

   oldtime& = timeGetTime()
    'code in here

   deltamillisec& = timeGetTime() - oldtime&

* Use the DoEvents statement in loops that take a long time to process
  (ex: 15+ seconds).  The DoEvents statement causes VB to yield execution
  so that Microsoft Windows can process events.  You should block further
  calls to the routine while it processes or the user may cause recursion
  (re-entry into the same code).  The usual effect of recursive programs
  in VB is a stack overflow error.

Return to Phil's Web Page

Created by: Philip