VB Script Objects
VB Script Objects
VB Script Objects
************************************************
Visit:
www.gcreddy.com
for QTP Scripts and Other Info
************************************************
Dictionary Object
Dictionary Object that stores data key, item pairs.
Add Method
Exists Method
gcreddy 1
QTP Training
Items Method
Keys Method
Remove Method
RemoveAll Method
The RemoveAll method removes all key, item pairs from a Dictionary
object.
Example:
Dim cities
Set cities = CreateObject("Scripting.Dictionary")
cities.Add "h", "Hyderabad"
cities.Add "b", "Bangalore"
cities.Add "c", "Chennai"
CompareMode Property
Sets and returns the comparison mode for comparing string keys in a
Dictionary object.
Key Property
Item Property
Sets or returns an item for a specified key in a Dictionary object. For
collections, returns an item based on the specified key. Read/write.
gcreddy 2
QTP Training
Examples:
1) add Elements AddDictionary
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
colKeys = objDictionary.Keys
Wscript.Echo "First run: "
For Each strKey in colKeys
Wscript.Echo strKey
Next
objDictionary.RemoveAll
colKeys = objDictionary.Keys
Wscript.Echo VbCrLf & "Second run: "
For Each strKey in colKeys
Wscript.Echo strKey
Next
gcreddy 3
QTP Training
colKeys = objDictionary.Keys
objDictionary.Remove("Printer 2")
colKeys = objDictionary.Keys
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
Wscript.Echo objDictionary.Count
gcreddy 4