Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep timer running during msgbox

Status
Not open for further replies.

guitardave78

Programmer
Joined
Sep 5, 2001
Messages
1,294
Location
GB
Full of questions today lol
Is it possible to keep a timer counting while a msgbox is in the forground?

}...the bane of my life!
 
I believe that MsgBox is modal because of its implementation as a Function in VB, i.e. it returns a result. To call it as a non-modal dialog may require that you use the API version and possibly supply a callback routine.

It may be easier to simply use a non-modal form of your own.

In either case you may need to track your use of the dialog to handle cases where it is already displayed and your program wants to signal another alert.
 
Use the MessageBox API function which does not block the Timer events.

Place a command button and a timer on the form and try the following code.
___
[tt]
Option Explicit
Private 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
Private Sub Command1_Click()
MessageBox hwnd, Time, "Time", 0
End Sub
Private Sub Form_Load()
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
Caption = Time
End Sub[/tt]
 
Only in the example as Hypetia has shown. You can use it any place in your code.

....
your code
MessageBox hwnd, Time, "Time", 0
your code
....

It does not have to be in a Command Button
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top