How to add values in ‘Dictionary Object’?

Dictionary object  is similar to an array to add values or store multiple values as ‘Key/Item’ pairs.

Dim dict ‘ Create a variable.

Set dict = CreateObject(“Scripting.Dictionary”) ‘Create a dictionary object

dict.Add “Company”, “HP” ‘ Adding keys and corresponding items.

dict.Add “Tool”, “QuickTest Pro”

dict.Add “Website”, “LearnQTP”

dict.Add “Country”, “India”

Remove:

dict.Remove(“Website”)

RemoveAll:

dict.RemoveAll ‘ Clear the dictionary.

Change the value:

oDict("IN") = "India"

oDict.Key("IN") = "IND"

'Displays "India"

MsgBox oDict("IND")

'Displays "Empty"

MsgBox oDict("IN")

''Displays an error as the key IND is already associated with the value "India"

'oDict.Key("IN") = "IND"

Key existence check:

If dict.Exists(“Country”) Then

Msgbox  “Specified key exists.”

Else

Msgbox  “Specified key doesn’t exist.”

End If

Retrieve(get):

To get the key add the item(values) from a dictionary object,

E.g.,     i = dict.Items ‘ Get the items.

k = dict.Keys ‘ Get the keys.

For Each key in dict.Keys

msgbox key & ” : ” & dict(key)

Next

Comments

Popular posts from this blog

Is QA a easy job?

Latest Version of TestComplete

Successful tester