Nesting an Object within an Object in AutoHotkey

During the webinar yesterday someone mentioned working with Multi-dimensional arrays. I thought I’d go ahead and post my template of nesting objects within objects and talk through it in the hopes that it helps.

Here are a list of the functions I used:

ExploreObj from Learning one

ObjectToString from Capn Odin

m() from Maestrith (Author of AHK Studio)

Nesting an Object within an Object in AutoHotkey

Here is the code that I work through Nesting an Object within an Object in AutoHotkey

#SingleInstance,Force
var=
(
Email First_Name Last_Name Phone
[email protected] Joy Senilg 123.456.7801
[email protected] Joe Glines 234.654.4321
[email protected] Jon Seling 567.890.6543
[email protected] Jon Seling 345.234.1322
)
obj:={} ;Need to declare object first
;*********Use For loop over Var going line by line*********************
for i, row in Loopobj:=StrSplit(var,”`n”,”`r`n”) { ;Parse Var on each new line
IfEqual, i,1,continue ;Skip header row
;~ MsgBox % StrSplit(row,”`t”).1
Obj[StrSplit(row,”`t”).1]:={} ;Need to instanciate the object under the key so you can stuff data into it
Obj[StrSplit(row,”`t”).1].First_Name :=StrSplit(row,”`t”).2
Obj[StrSplit(row,”`t”).1].Last_Name :=StrSplit(row,”`t”).3
Obj[StrSplit(row,”`t”).1].Phone :=StrSplit(row,”`t”).4
}
MsgBox % Obj[“[email protected]”].Phone
m(obj)
;~ DebugWindow(“`n______Object to String____________`n” ObjectToString(Obj),1,1,0,0) ;show content
;~ DebugWindow(“`n______Explore Object____________`n” ExploreObj(Obj),0,1,400,0) ;show structure
;~ return

;********************Use a for loop to loop over all 2nd-level objects contained in OBJ***********************************
for k, v in Obj
data.= k a_tab v.First_name a_tab v.Last_Name a_tab v.Phone “`n”

DebugWindow(“`n______FOR LOOP____________`n” data,0,1,100,0)

Comments are closed.