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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

specify the time a message box is visible?

Status
Not open for further replies.

macinyart

Technical User
Nov 10, 2001
8
0
0
US
I have what at first seems a simple problem, specifying the time a message box shows. I would like to have a box that shows only a "vbOKOnly" utility but would then disappear after a specified time, like maybe 15 seconds. Any help with this would be appreciated. Thanks. Jack
 
I'm not sure if this would be the best way to solve this problem, but this is what I would probably do...

Set up a timer control and set it's interval to how often you want to check for a msgbox. Then use the FindWindow and FindWindowEx API functions to find your program and the msgbox. If the msgbox if found, have the timer push your button via API, and wala, your msgbox closes. If the msgbox is not found, the timer sub just simply exits.

It would be helpful if you would explain what your program does, and if this msgbox would be poping up randomly or by some action. With the information you currently gave us, its hard to give you a better answer.

Explain a little more and I'll give you a more reliable way to do whatcha need to do =)

-null
 
Thanks for the tip. The message box as it is now coded comes up in response to click event on a button. I would like for the message box to depart with the click event on the vnOKOnly button and also to disappear with time. Thanks again. Jack
 
The other option is to make your own form and Function. That way you can do what ever you want. Brad,
Hey! email me any time! Bradsvb@yahoo.com
 
macinyat,

In the case with the click event, if you are expecting either a msgbox box or a certain other window, you could set up a Do Until Loop to find your next window. If the message box is found, have the sub pause for however many seconds then click the link. If your click results without a msgbox, just have the sub exit. I'm assuming you know how to use the FindWindow and FindWindowEx API functions...


Private Sub Button1_Click()
Dim lngApp as long, lngMsgbox as long, lngOtherWin as long

Do Until lngMsgbox& <> 0 Or lngOtherWin& <> 0
lngApp& = FindWindow(wndClassName,wndCaption)
lngMsgbox& = FindWindowEx(lngApp&, 0&, wndClassName, wndCaption)
lngOtherWin& = FindWindowEx(lngApp&, 0&, wndClassName, wndCaption)
Loop

If lngMsgbox& <> 0 then
Pause 10 'Pauses 10 seconds via the Pause sub provided below
Call PushvbOK 'Make a simple sub that clicks OK
Else
'Do whatever if the other window is found
End if
End Sub


'Heres a little pause sub I used to use quite frequently

Public Sub Pause(Interval)
Dim current 'As Timer
current = Timer
Do While Timer - current < Val(Interval)
DoEvents
Loop
End Sub


I hope this helps a little bit more. It would definately werk better than just having the timer control fire at intervals throughout your program. Just make sure you don't get stuck in that Do Until Loop =)

-núll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top