Name
Dictionary Object
Createable
Yes
Library
Microsoft Scripting Runtime
Description
The Dictionary object is similar to a Collection object, except that it’s loosely based on the Perl associative array. Like an array or a Collection object, the Dictionary object holds elements, called items or members, containing data. A Dictionary object can contain any data whatsoever, including objects and other Dictionary objects. Access the value of these dictionary items by using unique keys (or named values) that are stored along with the data, rather than by using an item’s ordinal position as you do with an array. This makes the Dictionary object ideal when you need to access data that is associated with a unique named value.
You can access each item stored to a Dictionary object by
using the For Each ...Next construct. However, rather
than returning a variant containing the data value stored to the
Dictionary object as you would expect, it returns a variant
containing the key associated with the member. You then have to pass
this key to the Item method to retrieve the member, as the following
example shows:
Dim vKey
Dim sItem, sMsg
Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
oDict.Add "One", "Engine"
oDict.Add "Two", "Wheel"
oDict.Add "Three", "Tire"
oDict.Add "Four", "Spanner"
For Each vKey In oDict
sItem = oDict.Item(vKey)
sMsg = sMsg & sItem & vbCrLf
Next
MsgBox sMsgDictionary Object Properties
The Dictionary object includes the following four properties:
Property | Description ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access