On Feb 9, 2007, at 11:21 AM, Chris Griffin wrote:

I have a dictionary and I need to return an array of the values sorted in key order. My understanding is that the order of the keys is undefined. So I tried this:

Function GetList() As myValueObject()

Dim values() As myValueObject
Dim keys() As String

keys = myDictionary.Keys  <= Type mismatch error
values() = myDictionary.Values  <= Type mismatch error

keys.sortwith(values)

return values

End Function

Can I cast the Keys and Values to the right type? Shouldn't a Variant be assignable to anything? Or is the assumption that an array of Variants could contain different types and therefore cannot be assigned to an array of a specific type? Please tell me there is a way to do this without having to go through all the keys and/or values and assign them to the correctly declared array type.

A Variant is assignable. Variant arrays are not. You'll need to do the following.

dim keys() as String
dim values() as myValueObject
for i as Integer = 0 to myDictionary.Count - 1
  keys.Append myDictionary.Key(i)
  values.Append myDictionary.Value(myDictionary.Key(i))
next

keys.SortWith values

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to