Friday, September 30, 2011

Working with Dictionary Object

Set dictObj=Createobject("Scripting.Dictionary")
dictObj.Add "1","One"
dictObj.Add "2","Two"
dictObj.Add 3,"Three" 'Observe here i am passing key as a integer meaning we can pass different types as Key

msgbox dictObj.Count 'This method returns the number of keys

If dictObj.Exists(3) Then 'This method looks for the Key
msgbox "Key exists"
else
msgbox "Key does not exist"
End If

a=dictObj.Keys 'This method assigns all the keys to an array
For i=1 to dictObj.Count
msgbox dictObj.Item(a(i-1)) 'This method retrieves the value of the key
Next