A GUI UpDown In Lieu of InputBox Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
madmoneymike5
Posts: 16
Joined: 06 Apr 2019, 13:24

A GUI UpDown In Lieu of InputBox

06 Apr 2019, 13:33

Hello. In an effort to accomplish data validation (making sure the input data is a number and within a specified range), I think the best option would be to use an UpDown control in a GUI. Never used a GUI before and the help docs aren't much help in describing how to mimic the InpuBox functionality of waiting for the user to input an answer before continuing.

What I have so far:

Code: Select all

Gui, Add, Edit
Gui, Add, UpDown, vNumOfConditions Range1-4, 1
Gui, Add, Button, Default w80, OK
Gui, Show
This definitely shows an UpDown control, but the script doesn't stop and wait for a response like the InputBox does. Also, there isn't a cancel button nor does it disappear once the user has entered data. How do I accomplish all of this and also access the user's response (such as in an If-Then statement)?

Thanks!
kiwichick
Posts: 142
Joined: 21 Jan 2014, 22:03

Re: A GUI UpDown In Lieu of InputBox

06 Apr 2019, 21:49

Hi madmoneymike5,

I'm not an AHK expert at all but, from what I can see, you'll need to create the Cancel button just like you did with the OK button. And you need Return after Gui, Show so the Gui will stay open while waiting for user input. Does this help:

Code: Select all

Gui, Add, Edit
Gui, Add, UpDown, vNumOfConditions Range1-4, 1
Gui, Add, Button, Default w80, OK
Gui, Add, Button, x+m w80, Cancel
Gui, Show
Return

ButtonOK:
Gui, Submit
Msgbox % NumOfConditions

ButtonCancel:
ExitApp 
garry
Posts: 3775
Joined: 22 Dec 2013, 12:50

Re: A GUI UpDown In Lieu of InputBox

07 Apr 2019, 08:12

not sure ... just an example

Code: Select all

Gui, Add, Edit, vEd1
Gui, Add, UpDown, vNumOfConditions Range1-4, 1
Gui, Add, Button, Default w80 gA1, OK
Gui, Show
return
Guiclose:
exitapp
A1:
Gui,submit,nohide
msgbox,%NumOfConditions%
Guicontrol,1:,ed1,1   ;- set to 1
return
madmoneymike5
Posts: 16
Joined: 06 Apr 2019, 13:24

Re: A GUI UpDown In Lieu of InputBox

07 Apr 2019, 15:18

Thanks for this, guys! I'll try them as soon as I can. Quick question though...I have a separate GUI that displays a progress bar. How do I separate this GUI from that one so that it's a completely different one? I'm struggling to understand the documentation...

EDIT: Found my answer on YouTube:

GUI, Name_of_GUI: New/Add/Edit/Show etc...
GUI, Name_of_Second_GUI: New/Add/Edit Show etc...
Last edited by madmoneymike5 on 08 Apr 2019, 19:54, edited 1 time in total.
madmoneymike5
Posts: 16
Joined: 06 Apr 2019, 13:24

Re: A GUI UpDown In Lieu of InputBox

08 Apr 2019, 19:52

Ok. I'm pulling my hair out over this one.

I managed to make the GUI version of the InputBox. But in order to handle it, I have to use subroutines, right? (Or wrong??) However, this seems to break the loop that I need.

In Psuedo code...

Code: Select all

Display GUI 1 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
Display GUI 2 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.

Begin Loop

Do some stuff

Display GUI 3 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
Display GUI 4 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
Display GUI 5 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.

Do some more stuff

End Loop
I am getting the error: A "Return" must be encountered prior to this "}".

It points to the end-of-loop closing bracket.

So I add it. But then after the first run through the loop, it just sits there. It doesn't start back over at the top....? How do I get it to start the loop over again?


Example of actual code for GUIs in case that helps:

Code: Select all

;GUI TO ASK THE NUMBER OF RULES WE NEED TO LOOP THROUGH.
Gui, Num_of_Rules: New, -Resize -MaximizeBox -MinimizeBox -Border		;NEW GUI THAT PREVENTS RESIZING, REMOVES THE MAXIMIZE AND MINIMIZE BUTTONS, AND REMOVES THE WINDOWS FRAME
Gui, Num_of_Rules: Margin, 5, 5											;PLACES A MARGIN AROUND ALL THE CONTROLS OF 5 PIXELS.
Gui, Num_of_Rules: Font, S12 CDefault Bold, Arial						;CHANGES THE FONT ON THE GUI TO ARIAL SIZE 12 BOLD UNTIL CHANGED.
Gui, Num_of_Rules: Add, Text,, How many rules do you want to import?	;ADDS THE MAIN TEXT OF THE GUI.
Gui, Num_of_Rules: Add, Edit, vNumOfRules								;BUDDY CONTROL FOR THE FOLLOWING UPDOWN CONTROL.
Gui, Num_of_Rules: Add, UpDown, Range1-2500, 1							;UPDOWN CONTROL WITH A RANGE OF 1 TO 2500 AND A DEFAULT VALUE OF 1.
NumOfRules_TT := "Use your arrow keys on your keyboard to scroll much faster or key in your answer."
Gui, Num_of_Rules: Add, Button, Default w80 gNORButtonOK, OK			;OK BUTTON THAT IS THE DEFAULT BUTTON. CALLS NORBUTTONOK SUBROUTINE WHEN PRESSED.
Gui, Num_of_Rules: Add, Button, x+m w80 gNORButtonCancel, Cancel		;CANCEL BUTTON THAT CALLS THE NORBUTTONCANCEL SUBROUTINE WHEN PRESSED.
Gui, Num_of_Rules: Show, x1429 y515, Number of Rules					;SHOWS THE GUI, SETS ITS X AND Y COORDINATES, AND TITLES THE WINDOW.
OnMessage(0x200, "WM_MOUSEMOVE")
Return

NORButtonCancel:	;IF USER PRESSES CANCEL, EXIT THE APP.
ExitApp
Return

NORButtonOK:		;IF USER PRESSENT OK, SAVE THE VALUE AND MOVE ON TO THE NEXT QUESTION.
Gui, Num_of_Rules: Submit
just me
Posts: 9490
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: A GUI UpDown In Lieu of InputBox  Topic is solved

09 Apr 2019, 06:31

Pseudo code:

Code: Select all

Set Completed to false
Display GUI 1 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
Wait until Completed = True

Set Completed to false
Display GUI 2 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
Wait until Completed = True

Begin Loop
{
	Do some stuff

	Set Completed to false
	Display GUI 3 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
	Wait until Completed = True
	
	Set Completed to false
	Display GUI 4 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
	Wait until Completed = True

	Set Completed to false
	Display GUI 5 to ask a question requiring a numeric answer. Cancel button exits the app. OK button continues and submits the GUI.
	Wait until Completed = True

	Do some more stuff
}
End Loop

CancelButtonLabel: (shared by all GUIs)
Exit the app

OKButtonLabel:  (shared by all GUIs)
Submit the GUI (the default GUI for this label is the GUI containing the button)
Set Completed to true.
Return from this label

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 169 guests