I'm writing an AutoHotkey script which needs to display the value of an array variable, but it doesn't seem to be working properly.
MyArray := ["one", "two", "three"]
send MyArray[1] ; "MyArray[1]"
send MyArray%1% ; "MyArray"
send %MyArray1% ; <empty>
send % MyArray%1% ; <empty>
;send %MyArray%1% ; 'Error: Variable name missing its ending percent sign'
;send %MyArray%1%% ; 'Error: Empty variable reference (%%)'
;send %MyArray[1]% ; 'Error: Variable name contains an illegal character'
I've found posts on the AHK forums claiming I can use send %MyArray1%
or send % MyArray %1%
, but both commands just reference empty variables.
How do I send an array's value in an AutoHotkey script?
Assigning values to associative array variable elements can be done by using the assignment statement in which the array is named, the index value is specified and the corresponding element value is assigned.
Obtaining an array is a two-step process. First, you must declare a variable of the desired array type. Second, you must allocate the memory to hold the array, using new, and assign it to the array variable. Thus, in Java, all arrays are dynamically allocated.
Use a single %
to force expression mode for a single parameter.
MyArray := ["one", "two", "three"] ; initialize array
Send, % MyArray[1] ; send "one"
This can be combined with regular text using quotation marks ""
Send, % "The first value in my array is " MyArray[1]
Expression mode can be used with any command, including MsgBox and TrayTip.
MsgBox, % MyArray[1]
Traytip, , % "The first value is " MyArray[1]
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With