Store an array name and contents at a given position

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Store an array name and contents at a given position

04 May 2020, 03:55

I want to be able to search through multiple arrays and when the contents match the search item then store which array holds the search item and what position it is at. I thought the following would work:

Code: Select all

GetArray()
{
	Global
	GuiControlget, BK, pos

	SQC := ""
	loop, 50
	{
		if instr(AA[A_index], BKX) && instr(AA[A_index], BKY)
		SQC := "AA[" A_index "]"
	
		if SQC
		break
	}
	test := SQC
	msgbox, 4096, Square, %SQC%: %test%
}
I thought test would contain the value of the array but currently it is showing the same result as SQC. What have I done wrong? Ii I use:

Code: Select all

SQC := AA[A_index]
Then, as expected, I get the contents of the array twice. Whatever I try I can't get SQC to show the array and test to show the contents of the array. Will someone please put me out of my misery as I've been at this for hours now. Thanks.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Store an array name and contents at a given position

04 May 2020, 04:25

AFAIKS, your inStr() 'needles' are variables, but I can't see where you've declared them in the first place, and if not set globally, how their content should make it to the function??
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Store an array name and contents at a given position

04 May 2020, 04:57

I think I couldn't understand what he wanted. But if I got it right.

Code: Select all

SQC := "AA[" A_index "]" .  AA[ A_index ]
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Store an array name and contents at a given position

04 May 2020, 05:22

Thanks for the replies. The function is part of a larger code and the contents of the variables is not an issue. The issue is how to store the array and then retrieve its content. Thanks for the code:

Code: Select all

SQC := "AA[" A_index "]" .  AA[ A_index ]
Unfortunately that produces the same value in both SQC and test. Can someone explain why, in my original code test produces aa[A_index] and not the value stored in aa[A_index]? Thanks.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Store an array name and contents at a given position

04 May 2020, 05:36

because SCQ := "AA[1]" contains a string and assigning it to another variable doesnt dereference the string, it just copies it over
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Store an array name and contents at a given position

04 May 2020, 06:03

BoBo wrote:
04 May 2020, 04:25
AFAIKS, your inStr() 'needles' are variables, but I can't see where you've declared them in the first place, and if not set globally, how their content should make it to the function??
BKX and BKY are assigned values when this line is executed:

Code: Select all

GuiControlget, BK, pos
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Store an array name and contents at a given position

04 May 2020, 06:17

The reason your approach doesn’t work was explained by swagfag. So while you can’t accomplish your goal by dereferencing a string containing an array reference as you can with a simple variable name, this accomplishes what you described (as you probably are already aware):

Code: Select all

 GetArray()
{
	Global
	GuiControlget, BK, pos

	SQC := ""
	loop, 50
	{
		if instr(AA[A_index], BKX) && instr(AA[A_index], BKY)
		{
			 SQC := "AA[" A_index "]"
			 test := AA[A_Index]
			 break
		}
	}
	msgbox, 4096, Square, %SQC%: %test%
}
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Store an array name and contents at a given position

08 May 2020, 15:48

Thanks for the replies. In the end I gave up using arrays as I couldn't get it to work as I expected .

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 257 guests