Having trouble retrieving items from an associative array

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jmorr
Posts: 28
Joined: 23 Mar 2022, 15:26

Having trouble retrieving items from an associative array

07 Apr 2024, 00:32

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!]
Rohwedder
Posts: 7697
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Having trouble retrieving items from an associative array

07 Apr 2024, 01:04

Hallo,
try:

Code: Select all

Array := {a:"Apple", b:"Banana"}
nextkey := "a"
nextvalue := Array[nextkey]
MsgBox,% nextvalue ; Apple
jmorr
Posts: 28
Joined: 23 Mar 2022, 15:26

Re: Having trouble retrieving items from an associative array

25 Apr 2024, 22:58

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], CoffeeChaton, Google [Bot] and 107 guests