You’ve probably noticed that the display time stops when an application pops up VB’s built-in MsgBox. Although the system timer continues to tick, the timer control isn’t updated every second, nor do other events (such as painting) process. To update the timer, replace VB’s built-in MsgBox with the MessageBox API function. MessageBox-generated dialogs don’t stop the timer from updating, and they allow other normal processing, such as form painting:
' General Declarations in BAS modulePublic Declare Function MessageBox Lib _ "user32" Alias "MessageBoxA" (ByVal _ hWnd As Long, ByVal lpText As String, _ ByVal lpCaption As String, ByVal wType _ As Long) As Long' Call from within any form like this:Call MessageBox(Me.hWnd, _ "This is a test in API Message Box", _ "API Message Box", vbInformation)
To use this technique in VB3, declare all parameters in the API call as integer. While calling, pass MB_ICONINFORMATION as the last parameter, instead of vbInformation. You can find the constant value for MB_ICONINFORMATION in the CONSTANT.txt file. Note that many of the intrinsic VB constants used with MsgBox also work with the MessageBox API. Now for the best news about this workaround-it’s totally unnecessary under VB5! Timer (and other) events are never blocked by a MsgBox call when run from an EXE. It’s important to understand that they’ll still be blocked in the IDE, but take a look next time you compile and you’ll see your clock just keeps on ticking.