Jump to content

Can't use Exit in script.


Bagel
 Share

Recommended Posts

I have a script with multiple inputbox questions. Provided that I hit the Cancel button I would like the script to stop immediately and terminate execution and in some other cases I want to run a function when I hit the Cancel button. I can't get the script to Exit or redirect to my function at all. Here is an example script that demonstrates my problem:

#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>
#Include <File.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <Array.au3>

#pragma compile(inputboxres, true)

Opt("WinTitleMatchMode",2)

$BoxOne = Number(InputBox("Cancel 1", "Hitting the Cancel button should Exit the script."))
If @error = 1 Then Exit ; Cancel or Close pressed

$BoxTwo = Number(InputBox("Cancel 2", "You shouldn't see this since the script should be dead."))
If @error = 1 Then Exit ; Cancel or Close pressed

$BoxThree = Number(InputBox("Cancel 3", "This REALLY shouldn't be seen."))
If @error = 1 Then Exit ; Cancel or Close pressed

The Number function I kept to keep this as close to the way I'm using everything in my original script. Once I click the Cancel button on the input box for BoxOne the script continues to execute the following code instead of exiting as intended. What's going on here and how do I kill the script? I've tried searching for how to use @error properly  but haven't been able to find a solution.

Edited by Bagel
Link to comment
Share on other sites

Oh I see. So basically what I'm doing here is using @error on the Number function itself. So to make the result entered a number I would have to do something like this? :

#pragma compile(inputboxres, true)

Opt("WinTitleMatchMode",2)

$BoxOne = InputBox("Cancel 1", "Hitting the Cancel button should Exit the script.")
If @error = 1 Then Exit ; Cancel or Close pressed
$BoxOne = Number($BoxOne)

Need it to be a number. Thanks for the help.

Link to comment
Share on other sites

InputBox return a string.  Reading help file will help you understand the function.  Depends if you want the return string to be a number or not.  But remember that Number ("abc")  will return 0.

Link to comment
Share on other sites

@Bagel, you could create your own message box and use inputbox to receive only numbers

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Box = Message_box()
Switch $Box
    Case 1
        MsgBox(4096, "Cancel 1", "Hitting the Cancel button should Exit the script.")
    Case 2
        MsgBox(4096, "Cancel 2", "You shouldn't see this since the script should be dead.")
    Case 3
        MsgBox(4096, "Cancel 3", "This REALLY shouldn't be seen.")
    Case Else
        MsgBox(4096, "Alert", "Incorrect number")
EndSwitch

Func Message_box()
    Local $Form = GUICreate("Message_box", 311, 125, -1, -1)
    Local $Input = GUICtrlCreateInput("", 20, 83, 273, 21, $ES_NUMBER)
    GUICtrlCreateLabel("1 = Hitting the Cancel button should Exit the script.", 20, 10, 242, 17)
    GUICtrlCreateLabel("2 = You shouldn't see this since the script should be dead.", 20, 34, 278, 17)
    GUICtrlCreateLabel("3 = This REALLY shouldn't be seen.", 20, 56, 175, 17)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Input
                ExitLoop
        EndSwitch
    WEnd

    $read = GUICtrlRead($Input)
    GUIDelete($Form)

    Return $read
EndFunc   ;==>Message_box

 

Edited by Belini
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...