Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

(Solved) If Inputbox closed, Exit script?


  • Please log in to reply
7 replies to this topic
SomeRandomGuy
  • Members
  • 10 posts
  • Last active: Apr 03 2016 11:02 PM
  • Joined: 20 Apr 2011
Hello all,

This script is essentially the most complex thing I have written by myself using AHK :D .

I am reading about branching in my programming book and made this as a simple exorcise to understand it better.

The following code has a problem. I want to exit the script if the user decides to close any of the input boxes instead of inserting values. Currently if a user closes any of the input boxes, the script continues to run forcing the user to close all windows and so it does not work well.

To get this desired functionality, would I have to use WinWaitClose for all the windows or is there a better way to avoid this problem? :(

; Directives

#NoEnv ; Avoids checking empty variables to see if they are environment variables
#NoTrayIcon ; Hide Autohotkey tray icon
#Persistent ; Keep the script permanently running until the user closes it or ExitApp is encountered
#SingleInstance force ; Skips the dialog box and replaces the old instance automatically if the script is launched a second time while already running

; Number comparison module

; Compare 2 numbers and display a message box with the results

Inputbox, Var_Number_a, Number Comparison,,,,,,,,,Please type a number to compare
; First number input box

Inputbox, Var_Number_b, Number Comparison,,,,,,,,,Please type a number to compare
; Second number input box

If (Var_Number_a > Var_Number_b){

	Msgbox,, Results, %Var_Number_a% is greater than %Var_Number_b%,
}
; If the first number is larger than the second number, display message box

If (Var_Number_b > Var_Number_a){

	Msgbox,, Results, %Var_Number_b% is greater than %Var_Number_a%,
}
; If the second number is larger than the first number, display message box

If (Var_Number_b = Var_Number_a){

	Msgbox,, Results, %Var_Number_a% is Equal to %Var_Number_a%,
}
; If the first and second number are equal, display message box

Msgbox, 4, Please decide, Would you like to compare 2 more numbers?
	IfMsgBox Yes
		Reload
	Else
		Exitapp
; Display yes/no message box, if user chooses yes, reload script if no exit script


None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
Inputbox, Var_Number_a, Number Comparison,,,,,,,,,Please type a number to compare ; First number input box 
If Errorlevel
 ExitApp
Check the errorlevel after each Input

SomeRandomGuy
  • Members
  • 10 posts
  • Last active: Apr 03 2016 11:02 PM
  • Joined: 20 Apr 2011

Inputbox, Var_Number_a, Number Comparison,,,,,,,,,Please type a number to compare ; First number input box 
If Errorlevel
 ExitApp
Check the errorlevel after each Input


Awesome, I was unable to find documentation on If error level in AHK
I'm sure I missed it somehow. Anyone have a way to locate additional resources ? for this?

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
<!-- w -->www.autohotkey.com/docs/commands/InputBox.htm<!-- w -->
;)

SomeRandomGuy
  • Members
  • 10 posts
  • Last active: Apr 03 2016 11:02 PM
  • Joined: 20 Apr 2011

www.autohotkey.com/docs/commands/InputBox.htm
;)


\m/_<(o.o)>_\m/ 8)

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Just thought you might like this:
; Input -> var1
; Input -> var2
MsgBox % var1 (var1>var2 ? ">" : (var1<var2 ? "<" : "=")) var2
Have fun on your journey!

Hint: ternary

SomeRandomGuy
  • Members
  • 10 posts
  • Last active: Apr 03 2016 11:02 PM
  • Joined: 20 Apr 2011

Just thought you might like this:

; Input -> var1
; Input -> var2
MsgBox % var1 (var1>var2 ? ">" : (var1<var2 ? "<" : "=")) var2
Have fun on your journey!

Hint: ternary


Lol thanks. :p , Yeah I'll save this to my hdd with scrapbook. When I get to ternary I'll be sure to decrypt this. It's logical and I can see how it works.

For now I'll keep my 29 lines of code. :shock: :D

SomeRandomGuy
  • Members
  • 10 posts
  • Last active: Apr 03 2016 11:02 PM
  • Joined: 20 Apr 2011

Inputbox, Var_Number_a, Number Comparison,,,,,,,,,Please type a number to compare ; First number input box 
If Errorlevel
 ExitApp
Check the errorlevel after each Input


Thank you : ). I did view the documentation provided with Input box and the specific errorlevel section.