Bagel Posted September 17, 2019 Share Posted September 17, 2019 (edited) 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 September 17, 2019 by Bagel Link to comment Share on other sites More sharing options...
Nine Posted September 17, 2019 Share Posted September 17, 2019 Number function annihilates the inputbox result. Remove the Number function before to test @error “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Bagel Posted September 17, 2019 Author Share Posted September 17, 2019 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 More sharing options...
Nine Posted September 17, 2019 Share Posted September 17, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mikell Posted September 17, 2019 Share Posted September 17, 2019 6 hours ago, Bagel said: Need it to be a number You might use a regex (untested) to check if the returned string contains only digits If not StringRegExp($BoxOne, '^\d+$') Then Exit Link to comment Share on other sites More sharing options...
Nine Posted September 17, 2019 Share Posted September 17, 2019 Look also at StringIsDigit and StringIsInt functions to test the validity of the entered data. Then use Number function to convert it. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Belini Posted September 17, 2019 Share Posted September 17, 2019 (edited) @Bagel, you could create your own message box and use inputbox to receive only numbers expandcollapse popup#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 September 18, 2019 by Belini My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now