Thursday, June 4, 2009

Working with Dictionary Objects

A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" '
Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
msgbox d("a") ' retrieves the Athens
a = d.Keys ' Get the keys
b = d.Items ' Get the items.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & space(1) & b(i) & vbnewline ' Create return string.
msgbox s

No comments:

Post a Comment