Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting Item of Dictionary by Index # using VBA in Excel

I am trying to load a combo box with the last item in a dictionary. I am trying to do something like this ComboBox1.Value = NodeColl.Item(NodeColl.Count) which would work with a collection, but does something strange when using a dictionary instead.

like image 499
Ehudz Avatar asked May 25 '12 15:05

Ehudz


1 Answers

The behaviour is different because a Dictionary allows numeric keys.

Calling .Item actually adds an item with the given key so;

NodeColl.Item(NodeColl.Count)

Adds a new item with no value & a key corresponding to the count.

To access the ordinal item use .Items (which is an array of the items)

firstItem = NodeColl.Items(0)
lastItem  = NodeColl.Items(NodeColl.Count - 1)
like image 104
Alex K. Avatar answered Sep 23 '22 22:09

Alex K.