As indicated in the code below, I'm trying to create a function for displaying a GUI with up to 10 caller-customizable labels/entries. I've figured out the dynamic creation of the labels/entries (thanks to boiler, https://t.ly/AOxi ), the dynamic arrangement of them (thanks to rajat's SmartGUI Creator, https://t.ly/OgUt ), and how to ensure the script waits for my inputs (and me clicking "OK" or "Cancel") prior to proceeding with the remainder of the script ( https://t.ly/LVN1 ). However, currently, whenever I call the function (e.g. using the *test hotkey combination coded below), it seems to ALWAYS evalutate to True. Whereas, as indicated in the code below, I want it to evaluate to False if the "Cancel" button is clicked, thus preventing the caller's remaining scripts from running. Any clever dev out there know the proper code syntax to get it working as desired? Or perhaps a way to end a main routine (i.e. the caller) from within a subroutine (i.e. the function) all while keeping the script persistent? Thanks in advance.
Code: Select all
; Function for Displaying a GUI With Up to 10 Entries to Obtain User's Input(s)
; NOTE: Need to use ByRef Parameters to Return Multiple Values to the Caller.
; More Details Here: https://t.ly/nYak
funcUserInput(varTitle, varLabel1="N/A", ByRef varInput1="N/A", varLabel2="N/A", ByRef varInput2="N/A", varLabel3="N/A", ByRef varInput3="N/A", varLabel4="N/A", ByRef varInput4="N/A", varLabel5="N/A", ByRef varInput5="N/A", varLabel6="N/A", ByRef varInput6="N/A", varLabel7="N/A", ByRef varInput7="N/A", varLabel8="N/A", ByRef varInput8="N/A", varLabel9="N/A", ByRef varInput9="N/A", varLabel10="N/A", ByRef varInput10="N/A"){
Loop, 10 {
if (varLabel%A_Index% != "N/A"){ ; do not use [ ] because it's not a real array
Gui, Add, Text, x10 w150 h30 +Right, % varLabel%A_Index% ":" ; % followed by a space forces an expression, in which a literal : needs ""
Gui, Add, Edit, vvarInput%A_Index% xp+160 yp w300 h20 +Left, % varInput%A_Index% ;
}
}
Gui, Add, Button, x10 w80, OK ;
Gui, Add, Button, xp+380 yp w80, Cancel ;
Gui, Show,, %varTitle% ;
Pause, On ; Pause the Script Here and Wait for User Input
ButtonOK:
Pause, Off ; Unpause the Script Here and Submit User Input
Gui, Submit ; Save Each Control's Contents to its Associated Variable
Gui, Destroy ; Close the GUI and Clear All Controls from System Memory, Readying Function for Next Caller
return true ; Informs the Caller that User Input Was Received
ButtonCancel:
Pause, Off ; Unpause the Script Here and Cancel User Input
Gui, Cancel ; Hides the GUI Without Saving Each Control's Contents to its Associated Variable
Gui, Destroy ; Close the GUI and Clear All Controls from System Memory, Readying Function for Next Caller
return false ; Informs the Caller that User Input Was Canceled
}
:*:*test::
varInput1 := "Testing" ;
varInput2 := "Script" ;
if (funcUserInput("Enter Test Inputs", "Input 1", varInput1, "Input 2", varInput2)){ ; Gets All Test Inputs in 1 GUI vs 2 GUI...if Any :)
MsgBox, % "User Inputs Were Received and They Were:`n`n" varInput1 " " varInput2 ;
}
return