A Scripting.Dictionary is a standard object provided by the Microsoft Scriping Runtime (scrrun.dll) dependency. It allows you to store several "item"s with respective "key"s. Each item and key are "linked" together so that you can later use the key to get the item. There is always one item per key, and two keys cannot be the same value.
You can visualize this object as an array where each element has a "key" that can be used to access it that can be anything as opposed to being strictly a numeric index for that element. Literal use of the dictionary as a dictionary illustrates this: the key is a word or phrase and the item is the definition of that word.
To create a Dictionary, call the CreateObject() function with the string "Scripting.Dictionary" as the name:
Set Dict = CreateObject("Scripting.Dictionary")
The resulting object referenced by
Dict will be an empty dictionary object.
These properties are available from a dictionary object.
You may use the built-in CompareMode constants or the equivalent values enumerated in the Scripting Runtime:
Const BinaryCompare = 0 Const TextCompare = 1 Const DatabaseCompare = 2
You must set this property before adding any key-item pairs, but you can retrieve it at any time.
Returns the number of key-item pairs currently stored in the dictionary.
Sets or returns the item for the provided key in the dictionary. If you attempt to retrieve an item with a key that doesn't exist, the result will be an empty value.
You can use this property as an alternative to the Add() function if you do not want to check if the key already exists and you want to overwrite any previous item with that key.
This property is the default property of this object.
You may pass any type of value, including arrays and objects (using the
Set keyword), as the item in a dictionary (or even the key, but items with complex keys are harder to retrieve).
If the key is a string, retrieval/rewriting of the item is based on the CompareMode.
Item = Dict.Item(Key) Item = Dict(Key) Dict.Item(Key) = Item Dict(Key) = Item
Sets the value of the provided key to a different value. You cannot retrieve a value from this property.
This property can be used to "rename" an item.
Dict.Key(OldName) = NewName
These methods are available from a dictionary object.
Adds a key-item pair to a dictionary. The provided key must not already exist when this function is called. Use the Exists() function on the key if you want to check.
Dict.Add Key, Item
You may pass any type of value, including arrays and objects, as the item in a dictionary (or even the key, but items with complex keys are harder to retrieve).
If the key is a string, checking for duplicate keys is based on the CompareMode.
Returns a Boolean whether the specified key exists in the dictionary.
BoolValue = Dict.Exists(Key)
If the key is a string, checking whether the key exists is based on the CompareMode.
ArrItems = Dict.Items()
ArrKeys = Dict.Keys()
Removes the key-item pair from the dictionary by the provided key.
If the key is a string, searching is based on the CompareMode.
Removes all key-item pairs from the dictionary.