How to get values from Array?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
euras
Posts: 429
Joined: 05 Nov 2015, 12:56

How to get values from Array?

Post by euras » 26 Mar 2018, 05:58

It looks easy to get value from a simple array. like

Code: Select all

Msgbox % Array.1
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

Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: How to get values from Array?

Post by Nightwolf85 » 26 Mar 2018, 09:47

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

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: How to get values from Array?

Post by SpeedMaster » 26 Mar 2018, 11:35

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: 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)
}

euras
Posts: 429
Joined: 05 Nov 2015, 12:56

Re: How to get values from Array?

Post by euras » 26 Mar 2018, 12:51

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 :)

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: How to get values from Array?

Post by SpeedMaster » 27 Mar 2018, 11:10

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. :)
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 :think:
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)
}

Post Reply

Return to “Ask for Help (v1)”