Firstly, A collection is implemented "using" linked lists...
That doesn't mean it has all the functionality that they provide (such as forward scrolling) but it does mean that its the core of their contruction.
There are 2 factors that prove this :
1. Dynamically increased size
2. Ability to delete "intermediate" nodes without disturbing structure (element numbers are "shuffled")
As for the use of Collections with key references the best part is if you wish to store information regarding ComboBoxes, you wish to display a fanciful "text" as the dropdown but you want to return a CODE as the actual answer.
Unlike Access which has the wonderful ability to produce a multi-column dropdown and to provide which one is "bound" as far as the value being set... VB doesn't provide this (well none that I could find when I looked).
If you create the collection where each item is in fact the instance of a class with 3 fields (Code, Contents [Default] and Element) you can actually get it to reference BOTH ways.
With this above structure I can at any time find out either way what I am looking at.Code:---- MyNewClass ---- Public Code as string Public Contents as variant Public Element as long ---- MyNewClass ---- Dim reItem as New MyNewClass reItem.Code = "AM" reItem.Contents = "America" reItem.Element = cMyCol.Count cMyCol.Add reItem, reItem.Code
Of course the Element number has to be adjusted if you remove items from the collection but you set the collection up as a class and provide all the functionality required within that class.Code:For i = 1 to cMyCol.Count Msgbox cMyCol(i).Code Next I MsgBox cMyCol("AM").Element
The whole thing then works together to provide you with a duel referencing system that allows you to load ComboBoxes, ListBoxes, collections or anything else while being able to reference it either by element or by Key and still being able to find the back-reference.




Reply With Quote