Page 1 of 1

Having trouble retrieving items from an associative array

Posted: 07 Apr 2024, 00:32
by jmorr
I know that if I have an array Array := {a:"Apple", b:"Banana"}, I have to put the key in double quotes, as in var := Array["a"], but I can't figure out the syntax to use if the key is stored in a variable, as in

Code: Select all

nextkey := "a"
nextvalue := Array[nextkey]
I have tried enclosing nextkey in %s and preceding it with "". It must be something simple but I can't think what.

Grateful for any help.

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

Re: Having trouble retrieving items from an associative array

Posted: 07 Apr 2024, 01:04
by Rohwedder
Hallo,
try:

Code: Select all

Array := {a:"Apple", b:"Banana"}
nextkey := "a"
nextvalue := Array[nextkey]
MsgBox,% nextvalue ; Apple

Re: Having trouble retrieving items from an associative array

Posted: 25 Apr 2024, 22:58
by jmorr
Many thanks. That was actually the first thing I tried and it didn't seem to have worked, but it turns out the problem was elsewhere.