Stephen Bullen wrote:
Hi Alan,
. . .
Is there
any generic reason to avoid Collections and use Dictionary Objects instead?
It's a matter of personal preference. I find Dictionaries to be generally
faster and more flexible than Collections, mainly because:
- It has an Exists property to quickly determine if an element exists
- You can easily change the keys
- It has an Items property to retrieve the entire set of items as an array
- It has a Keys property to retrieve the entire set of keys as an array
The biggest thing it can't do is insert items within the list, so it's no
good if you need a set that can be reordered. Using them also requires a
reference to the Microsoft Scripting Runtime, but I've not found that to be a
problem.
Regards
Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk
Thanks very much, Stephen; I haven't worked much with collections and
until now not at all with dictionaries, so this is quite helpful.
Two other differences I noted: The Dictionary Object seems to be 0-based
(at any rate, myArray = x.Keys seems to be a 0-based array
notwithstanding an Option Base 1 Statement); and the Dictionary Object
seems to be case sensitive while the Collection Object is not, which can
in fact be a helpful distinction--See the procedure in my contemporary
posting "To declare or not to declare".
Thanks again,
Alan Beban