Sort a dictionary  
Author Message

PostPosted: Top

VB Scripts >> Sort a dictionary


I'm trying to sort a Script Dictionary. It has a string value in the keys &
an Object in the items (an AutoCAD layer object in this instance).

1. I can swap the keys (string) values as shown below, but the Items
(object) won't budge
Where an I going wrong?.

2. is there a way to swap both Keys/Items in one go ie Dict(0)=Dict(5)
instead of doing them separately?

3. I've seen a routine on MSN for sorting a dictionary ;en-us;246067
That sorts a string based dict, but a) I don't know how to change it so it
can accept objects & b) it creates arrays to do the sorting which confuses
me because I thought = Dict.Keys returns an array anyway.

Thanks in advance
Dave F.

Sub test()
Dim LayObj As AcadLayer
Dim DictSort As Variant
Dim Dict As New Dictionary ' script dictionary (scripting runtime ref)
Dim KK As Variant, It As Variant

With ThisDrawing
For Each LayObj In .Layers
Dict.Add LayObj.Name, LayObj ' store it - Key:Layer Name, Item:
Layer Object
Next ' Lay
End With ' thisdrawing
KK = Dict.Keys
It = Dict.Items ' these are OBJECTS not strings

KK(0) = KK(5) 'swaps the keys
It(0) = It(5)
End Sub

Visual Studio72