Array Syntax Question Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Array Syntax Question

02 Apr 2018, 11:46

Suppose I have a two dimensional associative array like this:

Code: Select all

SubArray1 := {Alpha : 1 , Beta : 2 , Gamma : 3}
SubArray2 := {Delta : 4 , Epsilon : 5 , Phi : 6}

MyArray := {First : SubArray1 , Second : SubArray2}
Are these two commands identical?

Code: Select all

MyVar := MyArray.First.Alpha
MyVar := MyArray[First,Alpha]
I ask because I need to dynamically reference the array, and MyArray.%Var1%.%Var2% throws an exception, while MyArray[Var1,Var2] seems to work.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Array Syntax Question

02 Apr 2018, 12:00

try this:

Code: Select all

SubArray1 := {Alpha : 1 , Beta : 2 , Gamma : 3}
SubArray2 := {Delta : 4 , Epsilon : 5 , Phi : 6}
MyArray := {First : SubArray1 , Second : SubArray2}

ff := "first"
al := "alpha"

MsgBox,, 1,  % MyArray.First.Alpha
MsgBox,, 2, % MyArray["First","alpha"]
MsgBox,, 3,  % MyArray[ff,al]
User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: Array Syntax Question  Topic is solved

02 Apr 2018, 20:41

I typically prefer MyArray[Var1][Var2]. It’s a few more keystrokes but it’s clearer to see each dimension I think.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], peter_ahk and 244 guests