Object Key Sort Disable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Peabianjay
Posts: 52
Joined: 07 Nov 2015, 22:50

Object Key Sort Disable

17 May 2016, 19:47

The keys in an object are automatically sorted, which (no doubt) is helpful in many situations. I'm sure it speeds up referencing, but sometimes I'd like them to stay in the defined order.
It's not hard to write a work-around, as shown here, but I don't care for the added code & maintenance necessary.

Code: Select all

simple := { Name: "First", Home: "Second", Colour: "Third" }

text := "This is in the wrong order: `r`n`r`n"
for each, field in simple
    text .= each ": " field "`r`n"

msgbox, % text

; --------------------------------------

index := { 1: "Name", 2: "Home", 3: "Colour" }

text := "This is in the correct order: `r`n`r`n"

for each, simplekey in index
    text .= simplekey ": " simple[simplekey] "`r`n"

msgbox, % text
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Object Key Sort Disable

17 May 2016, 22:07

How about "Dictionary" ?

Code: Select all

_ := ComObjCreate( "Scripting.Dictionary" )
_.Add( "Name", "First" )
_.Add( "Home", "Second" )
_.Add( "Colour", "Third" )
For k in _
   text .= k ": " _.Item(k) "`n"
Peabianjay
Posts: 52
Joined: 07 Nov 2015, 22:50

Re: Object Key Sort Disable

20 May 2016, 09:07

Very nice. Thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot] and 298 guests