How to code for x variables depending on user input

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
caliciferwolf
Posts: 4
Joined: 26 Sep 2022, 22:18

How to code for x variables depending on user input

Post by caliciferwolf » 26 Sep 2022, 22:24

I was trying to figure out how to make a inputbox asking the user how many terminals they need to adjust, then the script will create x amount of variables (in groups of 4) to have user input the terminal information.

Code: Select all

#SingleInstance, force

inputbox, vTID,, Enter the terminal ID, , 200, 135

Run, chrome.exe "https://xxx.xxx.com/Management/Accounts/ProcessorDetails/%vTID%?viewOnly=True" " --new-window "
sleep 1000
WinGetActiveTitle, activeWindow
WinMaximize, %activeWindow%
MouseMove 649, 699
sleep 100
MouseClick, Left, 649, 699, 2
Send ^c

inputbox, vBID,, Enter the bank ID, , 200, 135
MouseMove 1095, 700
sleep 100
MouseClickDrag, Left, 1095, 700, 936, 700
Send ^c
inputbox, vMID,, Enter a merchant ID, , 200, 135
inputbox, vPAN,, Enter a processing name, , 200, 135
Gui, Show, w200 h180, Auto settle
Gui, Add, Text, x0 y0, Confirm This 
Gui, Add, Text, x10 y20, Terminal ID:
Gui, Add, Text, x100 y20, %vTID%
Gui, Add, Text, x10 y50, Bank ID:
Gui, Add, Text, x100 y50, %vBID%
Gui, Add, Text, x10 y80, Merchant ID:
Gui, Add, Text, x100 y80, %vMID%
Gui, Add, Text, x10 y110, Industry:
Gui, Add, ComboBox, vIntegration altsubmit, ECommerce|MOTO|Restaurant|Retail|Check Services|Petroleum

Gui, Add, Button, gSend_Button, Send
Gui, Add, Button, gCancel_Button, Cancel
Gui,+AlwaysOnTop
return

So instead of inputbox, vTID,, Enter the terminal ID, , 200, 135, it asks how many terminals need to be adjusted then loops that many times to store all of the information, if that makes sense

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: How to code for x variables depending on user input

Post by mikeyww » 27 Sep 2022, 06:38

Welcome to this AutoHotkey forum!

Code: Select all

InputBox, qty, Quantity, How many?,, 300, 125
If qty is not integer
 Return
Gui, Font, s10
Loop, %qty%
 Gui, Add, Edit, w230 vitem%A_Index%
Gui, Add, Button, w230 Default, OK
Gui, Show,, Items
Return

ButtonOK:
Gui, Submit
Loop, %qty%
 MsgBox, % item%A_Index%
Return
Explained: Loop

caliciferwolf
Posts: 4
Joined: 26 Sep 2022, 22:18

Re: How to code for x variables depending on user input

Post by caliciferwolf » 01 Oct 2022, 21:42

Thank you for your reply on this one, how can I reference to these different fields?

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: How to code for x variables depending on user input

Post by mikeyww » 02 Oct 2022, 06:55

The answer is on line 14: item1, item2, item3...

Explained: A_Index
The built-in variable A_Index contains the number of the current loop iteration. It contains 1 the first time the loop's body is executed. For the second time, it contains 2; and so on.

caliciferwolf
Posts: 4
Joined: 26 Sep 2022, 22:18

Re: How to code for x variables depending on user input

Post by caliciferwolf » 02 Oct 2022, 23:34

I guess what I am trying to do is make it so for however many items in qty, it will loop, and add to a var so it can print lines for %item%%num% where num is increasing by each loop, so I can get items 1 -> however many there are. I tried doing itemnum := item num but that doesn't seem to work well

caliciferwolf
Posts: 4
Joined: 26 Sep 2022, 22:18

Re: How to code for x variables depending on user input

Post by caliciferwolf » 03 Oct 2022, 00:01

Code: Select all

#SingleInstance, force

InputBox, qty, Quantity, How many?,, 300, 125
If qty is not integer
 Return
Gui, Font, s10
Loop, %qty%
Gui, Add, Edit, w230 vitem%A_Index%
Gui, Add, Button, w230 Default gDefault, OK
Gui, Show,, Items
num := 0
return

Default:
Gui, submit
Gui, destroy

Gui, Add, Text, x0 y0, Results
Loop, %qty%
Gui, Add, Text,, %num%
MsgBox, num is %num%
Gui, Add, Button, w30 Default gDefault1, OK
Gui, Add, Button, w230 Default gRefresh, Refresh
Gui, Show,, Results

return

Default1:
Gui, submit

Refresh:
++num
MsgBox, itemnum1 is %item1%
MsgBox, itemnum2 is %item2%
MsgBox, itemnum3 is %item3%
MsgBox, itemnum4 is %item4%
MsgBox, itemnum5 is %item5%
MsgBox, itemnum6 is %item6%
Return
So instead of having to call to every item number, like seen in Refresh:, is there a way to have a variable on the end of item that automatically increases so it will show item1, cycle ends, then item2 etc.

(thanks for the help by the way, I appreciate your time

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: How to code for x variables depending on user input

Post by mikeyww » 03 Oct 2022, 05:55

You can use qty again. Forcing an expression by leading your command parameter with % enables the pseudo-array to be enumerated.

Code: Select all

InputBox, qty, Quantity, How many?,, 300, 125
If qty is not integer
 Return
Gui, Font, s10
Loop, %qty%
 Gui, Add, Edit, w230 vitem%A_Index%
Gui, Add, Button, w230 Default, Submit
Gui, Show,, Items
num := 0
Return

ButtonSubmit:
Gui, Submit
Gui, Destroy
Gui, Font, s10
Gui, Add, Text, w230, Results
Loop, %qty%
 Gui, Add, Text, wp, % item%A_Index%
Gui, Add, Button, y+20 wp Default, Show
Gui, Show,, Results
Return

ButtonShow:
Gui, Hide
Loop, %qty%
 MsgBox, % "Item number " A_Index " is " item%A_Index% "."
Return
Or:

Code: Select all

InputBox, qty, Quantity, How many?,, 300, 125
If qty is not integer
 Return
Gui, Font, s10
Loop, %qty%
 Gui, Add, Edit, w230 vitem%A_Index%
Gui, Add, Button, w230 Default, Submit
Gui, Show,, Items
num := 0
Return

ButtonSubmit:
Gui, Submit
Gui, Destroy
Loop, %qty%
 text .= (text > "" ? "`n" : "") item%A_Index%
Gui, Font, s10
Gui, Add, Text, w230, Results
Gui, Add, Text, wp  , %text%
Gui, Add, Button, y+20 wp Default, Show
Gui, Show,, Results
Return

ButtonShow:
Gui, Hide
Loop, %qty%
 MsgBox, % "Item number " A_Index " is " item%A_Index% "."
Return
Explained: Dynamic variables

Post Reply

Return to “Ask for Help (v1)”