Page 1 of 1
How to get values from Array?
Posted: 26 Mar 2018, 05:58
by euras
It looks easy to get value from a simple array. like
But if I have more complex array, then it doesn't work. what I'm doing wrong?
Code: Select all
First := {}
Queues = SKG,SKS,SKP
Loop parse, % Queues, % ","
{
temp_arr := {}
temp_arr.Push(A_LoopField)
First.Push({("Text" A_Index): temp_arr})
}
for x, y in First
for e, r in y
for t, o in r
content .= x A_Tab o A_Tab e "`n"
MsgBox % content
MsgBox % First.2.2 ; lets say I want to get a value from main Array's second line, 2 element
Re: How to get values from Array?
Posted: 26 Mar 2018, 09:47
by Nightwolf85
I think you are not understanding just how "complex" (and strange) your array is.
This gets what you want, but isn't intuitive, You need the first index number to match the number after
Text ie.
First[1]["Text1"] and also you need to have the
[1] at the end, which should always be a
1
Code: Select all
First := {}
Queues := "SKG,SKS,SKP"
Loop parse, % Queues, % ","
{
temp_arr := {}
temp_arr.Push(A_LoopField)
First.Push({("Text" A_Index): temp_arr})
}
for x, y in First
for e, r in y
for t, o in r
content .= x A_Tab o A_Tab e "`n"
MsgBox % content
MsgBox % First[2]["Text2"][1] ; lets say I want to get a value from main Array's second line, 2 element
Re: How to get values from Array?
Posted: 26 Mar 2018, 11:35
by SpeedMaster
euras wrote:what I'm doing wrong?
Nightwolf85 wrote:I think you are not understanding just how "complex" (and strange) your array is.
+1
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
I recommend to use
st_printarr() function to see what's going wrong
https://autohotkey.com/boards/viewtopic ... f1e5deac0f
Code: Select all
First := {}
Queues := "SKG,SKS,SKP"
Loop parse, % Queues, % ","
{
temp_arr := {}
temp_arr.Push(A_LoopField)
First.Push({("Text" A_Index): temp_arr})
}
for x, y in First
for e, r in y
for t, o in r
content .= x A_Tab o A_Tab e "`n"
MsgBox % content
MsgBox % First[2]["Text2"][1] ; lets say I want to get a value from main Array's second line, 2 element
;String Things by tidbit
msgbox, % st_printarr(first)
;String Things by tidbit
;https://autohotkey.com/boards/viewtopic.php?f=6&t=53&sid=5c401643235e7a2e73d769f1e5deac0f
st_printArr(array, depth=5, indentLevel="")
{
for k,v in Array
{
list.= indentLevel "[" k "]"
if (IsObject(v) && depth>1)
list.="`n" st_printArr(v, depth-1, indentLevel . " ")
Else
list.=" => " v
list.="`n"
}
return rtrim(list)
}
Re: How to get values from Array?
Posted: 26 Mar 2018, 12:51
by euras
Nightwolf85 wrote:I think you are not understanding just how "complex" (and strange) your array is.
What I'm doing here, I add one array into another. Lets say the tool gather some type of information first, then gather second type information and I want to have it all in a one
mother array. That's the method I'm using and it works. If it is a stupid method and I should use another one, I will be happy to get that method's example
![Smile :)](./images/smilies/icon_e_smile.gif)
Re: How to get values from Array?
Posted: 27 Mar 2018, 11:10
by SpeedMaster
euras wrote:
Lets say the tool gather some type of information first, then gather second type information and I want to have it all in a one
mother array. That's the method I'm using and it works.
![Smile :)](./images/smilies/icon_e_smile.gif)
I think you are trying to make a
constructor to build your own custom object but you are unclear about the object your want to build
I see 4 output possibilities firstA, firstB, firstC or firstD.
Code: Select all
firstA:=[["SKG","text1"],["SKS","text2"],["SKP","text3"]]
firstB:=[["text1","SKG"],["text2","SKS"],["text3","SKP"]]
firstC:=[{"SKG":"text1"},{"SKS":"text2"},{"SKP":"text3"}]
firstD:=[{"text1":"SKG"},{"text2":"SKS"},{"text3":"SKP"}]
msgbox, % "firstA:`n" . st_printarr(firstA)
msgbox, % "firstB:`n" . st_printarr(firstB)
msgbox, % "firstC:`n" . st_printarr(firstC)
msgbox, % "firstD:`n" . st_printarr(firstD)
;String Things by tidbit
;https://autohotkey.com/boards/viewtopic.php?f=6&t=53&sid=5c401643235e7a2e73d769f1e5deac0f
st_printArr(array, depth=5, indentLevel="")
{
for k,v in Array
{
list.= indentLevel "[" k "]"
if (IsObject(v) && depth>1)
list.="`n" st_printArr(v, depth-1, indentLevel . " ")
Else
list.=" => " v
list.="`n"
}
return rtrim(list)
}