|
|
|
Not all developers know that Timer controls in compiled VB5 and VB6 applications aren't stopped by MsgBox statement, so the Timer's Timer event procedure is regularly executed even when the message box is being displayed on the screen.
However, inside interpreted applications under all VB versions, Timers are stopped when a MsgBox is active, which means that, if you rely on the code in the Timer event procedure, you can't completely test and debug your app withing the VB environment.
To do so, you must use the MessageBox API function instead of the built-in MsgBox function. The API function has a similar syntax, but it takes an additional argument that states the parent window of the message box dialog (you can use Me.hWnd), and the order of the Title and Buttons arguments is reversed. Even more interesting, all the VB constants can be used without any problem for the Buttons argument: |
To test this function, create a new form and place one timer, one label, and two command buttons on its surface, then type this code: |
Click here to copy the following block | Private Sub Command1_Click() MsgBox "The Timer STOPS!", vbOKOnly, "Regular MsgBox" End Sub
Private Sub Command2_Click() MessageBox Me.hWnd, "The Timer DOESN'T STOP", "MessageBox API function", _ vbOKOnly + vbExclamation End Sub
Private Sub Timer1_Timer() Label1.Caption = Time End Sub |
Even better, you can wrap the API function into a MsgBox-like function that takes the same arguments in the same order: |
Click here to copy the following block | Function MsgBox2(Prompt As String, Optional Buttons As VbMsgBoxStyle, _ Optional Title As Variant) As VbMsgBoxResult If IsMissing(Title) Then Title = App.Title MsgBox2 = MessageBox(Screen.ActiveForm.hWnd, Prompt, Title, Buttons) End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|