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

Setting timer to close a message box 1

Status
Not open for further replies.

LearningAsIGo

Technical User
Mar 17, 2008
18
0
0
US
I was wondering if anyone could point me in the right direction to find out how to set a timer to automatically click close a MsgBox statement after 5 seconds. i don't have any code started for a timer or anything because i don't know where to begin looking. Any help would be appreciated.
 
You can't do it with a MsgBox, but you can do it with a DialogBox.

Code:
Function FileDlgFunc(identifier$, action, suppvalue)
  FileDlgFunc = True
  Select Case action
    Case 1
      DlgText("ForTiming"), Now() + (CInt(DlgText("ForTiming")) / (24 * 60 * 60))
      DlgVisible "ForDisplay", 0
      DlgVisible "ForTiming", 0
      DlgVisible "TxtTitle", 0
      DlgVisible "BtnJunk", 0
      Select Case DlgText("ForDisplay")
        Case "0"
          DlgVisible "BtnYes", 0
          DlgVisible "BtnAbort", 0
          DlgVisible "BtnRetry", 0
          DlgVisible "BtnNo", 0
          DlgVisible "BtnCancel", 0
          DlgVisible "BtnIgnore", 0
          DlgFocus "BtnOK"
        Case "1"
          DlgVisible "BtnYes", 0
          DlgVisible "BtnAbort", 0
          DlgVisible "BtnRetry", 0
          DlgVisible "BtnNo", 0
          DlgVisible "BtnIgnore", 0
          DlgFocus "BtnOK"
        Case "2"
          DlgVisible "BtnOK", 0
          DlgVisible "BtnYes", 0
          DlgVisible "BtnNo", 0
          DlgVisible "BtnCancel", 0
          DlgFocus "BtnAbort"
        Case "3"
          DlgVisible "BtnOK", 0
          DlgVisible "BtnAbort", 0
          DlgVisible "BtnRetry", 0
          DlgVisible "BtnIgnore", 0
          DlgFocus "BtnYes"
        Case "4"
          DlgVisible "BtnOK", 0
          DlgVisible "BtnAbort", 0
          DlgVisible "BtnRetry", 0
          DlgVisible "BtnCancel", 0
          DlgVisible "BtnIgnore", 0
          DlgFocus "BtnYes"
        Case "5"
          DlgVisible "BtnOK", 0
          DlgVisible "BtnYes", 0
          DlgVisible "BtnAbort", 0
          DlgVisible "BtnNo", 0
          DlgVisible "BtnIgnore", 0
          DlgFocus "BtnRetry"
      End Select
    Case 2
      FileDlgFunc = False
  End Select

  If Now() >= DlgText("ForTiming") Then
    AppActivate DlgText("TxtTitle")
    SendKeys "{ESC}"
  End If
End Function

Function ClosableMsgBox(Prompt$, Buttons%, Title$, Seconds%) As Integer
  Dim iHeight As Integer
  iHeight = CInt(Len(Prompt) / 120) + 10
  If Buttons < 0 Or Buttons > 5 Then
     ClosableMsgBox = 50
     Exit Function
  End If
  Begin Dialog DlgConfirm 250, iHeight + 30, Title, .FileDlgFunc
    Text 5,  5, 240, iHeight, Prompt
    Text 0,  0, 1, 1, CStr(Buttons), .ForDisplay
    Text 0,  0, 1, 1, CStr(Seconds), .ForTiming
    Text 0,  0, 1, 1, Title, .TxtTitle
    ButtonGroup .Btns
    CancelButton  0, 0, 1, 1, .BtnQuit
    PushButton 0, 0, 1, 1, "Junk", .BtnJunk
    PushButton  5, iHeight + 10, 40, 15, "OK", .BtnOK
    PushButton  95, iHeight + 10, 40, 15, "Cancel", .BtnCancel
    PushButton  5, iHeight + 10, 40, 15, "Abort", .BtnAbort
    PushButton  50, iHeight + 10, 40, 15, "Retry", .BtnRetry
    PushButton  95, iHeight + 10, 40, 15, "Ignore", .BtnIgnore
    PushButton  5, iHeight + 10, 40, 15, "Yes", .BtnYes
    PushButton  50, iHeight + 10, 40, 15, "No", .BtnNo
  End Dialog
  Dim MyDialog As DlgConfirm
  On Error Resume Next
  Dialog MyDialog
  If Err Then
    ClosableMsgBox = 50
  Else
    ClosableMsgBox = MyDialog.Btns
  End If
  On Error Goto 0
End Function

Sub Main
  Dim iValue%, iButtons%, iSeconds%
  Dim sPrompt$, sTitle$
    
  iButtons = 1
  iSeconds = 5
  sPrompt = "Please confirm this message within " & CStr(iSeconds) & " seconds."
  sTitle = "Hello World"

  iValue = ClosableMsgBox(sPrompt, iButtons, sTitle, iSeconds)
  MsgBox CStr(iValue), 0, "Returned Value"
End Sub
 
Wow! Thank you! I think its a bit more than I need, but learning what each function does will be fun...
Is there a refrence book or manual that I can buy to help me code better?
 
EB has a help file that does a fair job of explaining things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top