Using : XOJO 2018r4 Lite version for Windows.
Following code exists in my program.
newKitList is a collection and puNewKitList is a PopUpMenu.
Getting the pairs of the Collection into the PopUpMenu works fine with this code.
Dim i As Integer
puNewKit.DeleteAllRows
For i = 1 To newKitList.Count
puNewKit.AddRow newKitList.Item(i) + " [" + newKitList.Key(i) + "]"
puNewKit.RowTag(i-1) = newKitList.Key(i)
Next
BUT. Instead of a collection I created a Dictiobary because Collection is Deprecated and should be replaced by Dictionary.
I cannot found out how I can do the same thing with a Dictionary as i did with a Collection .
Can anybody help me please.
Regards
Etienne
@Volbragt Etienne There are two solutions to get a Dictionary item (also remember that indexes begin at 0 with Dictionaries)
- Access it by key
Dim i As Integer
puNewKit.DeleteAllRows
For i = 0 To newKitList.Count - 1
dim key as Variant = newKitList.Key(i)
puNewKit.AddRow newKitList.Value( key ) + " [" + key + "]"
puNewKit.RowTag(i-1) =key
Next
- Use the Keys() and Values() arrays of a Dictionary (usually faster)
[code]Dim i As Integer
puNewKit.DeleteAllRows
dim allKeys() as Variant = newKitList.Keys
dim allValues() as Variant = newKitList.Values
For i = 0 To ubound( allKeys )
dim key as Variant = allKeys( i )
puNewKit.AddRow allValues( i ) + " [" + key + “]”
puNewKit.RowTag(i-1) =key
Next[/code]
@StphaneMons
Thanks, both the codes work fine . Just make the correction for the RowTag index : (i) instead of (i-1).
I did not declare the : Dim key As Variant = …
in my code that i tried.
Thanks a lot
Regards
Keep in mind that order in a Dictionary is arbitrary.