Next key-value pair in assosiative array

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
julka
Posts: 14
Joined: 06 Feb 2014, 02:31

Next key-value pair in assosiative array

22 May 2014, 21:26

Let's assume we have

Code: Select all

array:=[1:"a",3:"b",1000:"c"]
and we have key=3. How can I go from key=3 to key=1000?

Using for-loop is not an option since this line will be called millions of times.

I could get all keys before calling this line, if needed.

Perhaps Enumerator Object could do the trick?
Hamlet
Posts: 32
Joined: 02 Oct 2013, 09:55
Location: Seoul, Korea

Re: Next key-value pair in assosiative array

22 May 2014, 21:43

.
Last edited by Hamlet on 22 May 2014, 22:36, edited 2 times in total.
nimda
Posts: 34
Joined: 18 Dec 2013, 14:06

Re: Next key-value pair in assosiative array

22 May 2014, 21:51

Until someone with more knowledge of AHK's inner workings comes along, you might try this:

Code: Select all

array:={1:"a",3:"b",1000:"c"}
linked := {}

for key in array
{
    if (A_Index > 1)
        linked[previous_key] := key
    previous_key := key
}

MsgBox % linked[3]
julka
Posts: 14
Joined: 06 Feb 2014, 02:31

Re: Next key-value pair in assosiative array

22 May 2014, 22:12

Linked works, ty. How I didn't thought of it myself -.-

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 333 guests