Jump to content

Getting Timeout of a MsgBox ??


Solchael
 Share

Recommended Posts

Hello everyone, how are you all ? 

I am new here, so I hope it's the right place to ask. If no, then apologies and if a moderator can move it to the correct section. 

I am completly new to coding and new to AutoIt. And I am trying to get the result of the Timeout of a MsgBox. 

IE : If timeout is over then desplay a message
      Else continue

the code

$iTimeout = 10
$s_currentday = InputBox ("Tutoriel" , "Which day of the week are we??", "Enter a day" , "" , 200, 130, Default, Default, $iTimeout)


If $iTimeout <> 0 then
    MsgBox ( 16, "Tutoriel", "Too long to answer, programe will close!!")
Else
    Switch $s_currentday
        Case "Monday"
            MsgBox ( 0, "Tutoriel", "It's only the start of the week!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox = 6 Then
                    MsgBox ( 0, "Tutoriel", "It's the start of an awesome week!")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow will be a better day!")
                EndIf
        Case "Tuesday"
            MsgBox ( 0, "Tutoriel", "Second day of the week!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox = 6 Then
                    MsgBox ( 0, "Tutoriel", "Let's make this week and amazing one!")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow will be a better day!")
                EndIf
        Case "Wednesday"
            MsgBox ( 0, "Tutoriel", "Third day of the week!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox == 6 Then
                    MsgBox ( 0, "Tutoriel", "Half of the week and yet more good stuff to come!")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow will be a better day!")
                EndIf
        Case "Thursday"
            MsgBox ( 0, "Tutoriel", "Closer to the weekend!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox = 6 Then
                    MsgBox ( 0, "Tutoriel", "We are close to end the week! Keep that positive mind")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow will be a better day!")
                EndIf
        Case "Friday"
            MsgBox ( 0, "Tutoriel", "Almost weekend!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox = 6 Then
                    MsgBox ( 0, "Tutoriel", "It's the start of an awesome weekend! Think of what you are going to do!")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow will be a better day! Maybe you can go out and have a drink with your friends?")
                EndIf
        Case "Saturday"
            MsgBox ( 0, "Tutoriel", "It's the start of the weekend!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox = 6 Then
                    MsgBox ( 0, "Tutoriel", "It's the start of an awesome weekend!")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow is Sunday, you can rest and have a good day with your friends and/or family!")
                EndIf
        Case "Sunday"
            MsgBox ( 0, "Tutoriel", "We are almost at the end of the week!")
            $mybox = MsgBox ( 4, "Tutoriel", "Do you feel good?")
                If $mybox = 6 Then
                    MsgBox ( 0, "Tutoriel", "It's the end of an awesome week! And I am sure that the next one will be even better!")
                ElseIf $mybox = 7 Then
                    MsgBox ( 0, "Tutoriel", "Don't worry tomorrow will be the start of a new week! So new chance to feel better")
                EndIf
    EndSwitch
EndIf

Sorry for my bad english, not my main language. 

Thanks in advance, 
Solchael

Link to comment
Share on other sites

Your title refers to MsgBox.  I assume you meant InputBox.

You want to look at the value of @error to see if the dialog was cancelled or timed out.

Example:

#include <Constants.au3>

$sValue = InputBox("Test", "Enter anything you like", "", "", -1, -1, Default, Default, 5)
If @error Then
    Switch @error
        Case 1 ;Cancelled
            MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "INFO", "User cancelled input box")
        Case 2 ;Timed out
            MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "INFO", "Input box timed out")
        Case Else ;Other error
            MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Input box failed - @error = " & @error)
    EndSwitch
    Exit
EndIf

MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "INFO", "You entered:" & @LF & @LF & $sValue)

 

Welcome to the forum!  :bye:

Edited by TheXman
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

There is a limit of 5 or 10 posts before you can edit your posts.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

16 minutes ago, TheXman said:

You want to look at the value of @error to see if the dialog was canceled or timed out.

Example:

#include <Constants.au3>

$sValue = InputBox("Test", "Enter anything you like", "", "", -1, -1, Default, Default, 5)
If @error Then
    Switch @error
        Case 1
            MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "INFO", "User cancelled input box")
        Case 2
            MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "INFO", "Input box timed out")
        Case Else
            MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Input box failed - @error = " & @error)
    EndSwitch
    Exit
EndIf

MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "INFO", "You entered:" & @LF & $sValue)

 


Thank you. I just didn't read properly the Function InputBox .... It's clearly written ... Maybe I need another pair of glasses : 
 

Return Value

Success: the string that was entered.
Failure: "" (empty string) and sets the @error flag to non-zero.
@error: 1 = The Cancel button was pushed.
2 = The Timeout time was reached.
3 = The InputBox failed to open. This is usually caused by bad arguments.
4 = The InputBox cannot be displayed on any monitor.
5 = Invalid parameters width without height or left without top.

 

16 minutes ago, water said:

Welcome to AutoIt and the forum!

There is a limit of 5 or 10 posts before you can edit your posts.

Thank you very much for the info. Couldn't find it.

Regards,
Solchael

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...