Visual Basic/Dictionaries

Dictionary class provides some functions beyond those provided by Collection class. A dictionary is a list of key, value pairs. Unlike Collection, Dictionary class is only available via Microsoft Scripting Runtime, a reference to which needs to be added to your project in order to use the class.

Creating a dictionary:

Adding a key and an item to a dictionary:

Accessing an item by key:

Accessing an item by index:

Iterating through the keys:

Iterating through the values:

Removing an item:

Removing all items or emptying:

Size or number of elements:

Testing for emptiness:

Changing the key of an item:

Changing the value of an item:

Testing for presence of a key:

Using dictionary as a set:
 * Associate the dummy value 1 with each element of the set.
 * When adding an item, test for existence.