SlideShare a Scribd company logo
Dictionary Object In QTP :
The Dictionary object is used to hold a set of data values in the form of (key, item) pairs.
It is also known as 'Associative Array' because it associates a key with an item.
If you compare it with an Array, Keys are similar to the indices in an array. But here Keys are not
numetic Indices like we have in array ranther than these are
arbitrary strings normally. Each key in a single Dictionary object must be unique.
Dictionary Object is a part of VB Script and so it can be used with the tools supporting VBS.
(Here we will talk how it used in QTP).
Dictionary object is COM object(Component Object Model) and “Scripting.Dictionary” is the ProdID
for Disctionary object.
It can be instantiated as following:
Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
Using Add method we can add fdifferent keya and pair values to the structure.
Set oDict = CreateObject("Scripting.Dictionary")
oDict.Add "Tool1", "Selenium"
oDict.Add "Tool2", "QTP"
oDict.Add "Tool3", "Silk Test"
Then it should look like
Key Value
Tool1 Selenium
Tool2 QTP
Tool3 Silk Test
To fetch the data from the Dict object we can use .Item method.
Msgbox oDict.item("Tool2") -- Should return respective item value i.e QTP
The problem with Dictionary object is, if you try to access any item which is not even
present in the Dictionary,it does not result in an error. Instead, the non-existent element
is added to the Dictionaty object.
Set oDict = CreateObject("Scripting.Dictionary")
oDict.Add "Tool1", "Selenium"
oDict.Add "Tool2", "QTP"
oDict.Add "Tool3", "Silk Test"
MsgBox oDict.Item("Tool4")
Here no ArrayIndexOutOfBoundsException occurs, rather than Tool4, is added to the Dictionary, along
with the item value Null.
Looping through the Items in Dictionary Object:
Dim oItem
Dim sItem, sMsg
Dim oDict
Set oDict = CreateObject("Scripting.Dictionary")
Set oDict = CreateObject("Scripting.Dictionary")
oDict.Add "Tool1", "Selenium"
oDict.Add "Tool2", "QTP"
oDict.Add "Tool3", "Silk Test"
For Each oItem In oDict
sItem = oDict.Item(oItem )
sMsg = sMsg & sItem & vbCrLf
Next
MsgBox sMsg
Dictionry object having only one configurable property, Compare Mode.
If its is created in binary mode, which means each key in the Dictionary is based on its ASCII value.
Means lowercase and upper cases are treated as different here.
When a Dictionary is configured in text mode, uppercase and lowercase letters are treated identically.
0 – Sets the mode to binary. This is the default value.
1 – Sets the mode to text.
Set oDict = CreateObject("Scripting.Dictionary")
oDict.CompareMode = 1
Initially while creating only youi can set the compare mode.Once it is alreday having any element, you
are not allowed
to change the compare mode.
To reconfigure the Dictionary mode, you first need to remove all items from the Dictionary.
To remove a value from a dictionary, use the .Remove method and specify the key to remove. For
example:
oDict.Remove “Tool2"
To remove all values and clear the dictionary, use the .RemoveAll method. Use the .Count property to
obtain a count of values in the dictionary.
The .Keys and .Items methods return an array containing all the keys or items from the dictionary. For
example:
aTools = oDict.Keys
aNames = oDict.Items

More Related Content

PPTX
Chapter 6.3
PPT
Chapter 1 Presentation
PPTX
Vectors in Java
PDF
Collection framework (completenotes) zeeshan
PDF
Lecture 7- Iterator and for loop over arrays
ODP
Databases and doctrine
PDF
Lecture20 vector
PPTX
Learn ActionScript programming myassignmenthelp.net
Chapter 6.3
Chapter 1 Presentation
Vectors in Java
Collection framework (completenotes) zeeshan
Lecture 7- Iterator and for loop over arrays
Databases and doctrine
Lecture20 vector
Learn ActionScript programming myassignmenthelp.net

What's hot (19)

PPT
Js objects
PPTX
Dynamic databinding
PPTX
Function Java Vector class
PPTX
Any Which Array But Loose
PDF
ознакомления с модулем Entity api
PDF
PPT
packaging procedures_and_state
PPTX
java object oriented presentation
PPT
Iterator Design Pattern
PPT
Generics collections
PPTX
mediator
PPT
Lesson3
PDF
Python Dictionary
PPTX
Javasession7
PDF
Ts archiving
PPT
Reversing JavaScript
PPTX
Joshua bloch effect java chapter 3
PPTX
Pi j3.4 data-structures
PPTX
Java tutorial part 4
Js objects
Dynamic databinding
Function Java Vector class
Any Which Array But Loose
ознакомления с модулем Entity api
packaging procedures_and_state
java object oriented presentation
Iterator Design Pattern
Generics collections
mediator
Lesson3
Python Dictionary
Javasession7
Ts archiving
Reversing JavaScript
Joshua bloch effect java chapter 3
Pi j3.4 data-structures
Java tutorial part 4
Ad

Similar to Basics of dictionary object (20)

DOCX
descriptive programming
PPTX
PYTHON OBJECTS - Copy.pptx
PPTX
Untitled dictionary in python program .pdf.pptx
PPTX
Javascript Objects Deep Dive
PPT
Java: Objects and Object References
PDF
Persistence And Documents
ODP
Eqela Core API and Utilities
PPTX
python full notes data types string and tuple
PPTX
Comparable/ Comparator
PDF
Functional Core, Reactive Shell
PDF
JavaScript Programming
PPTX
Object oriented database concepts
PPTX
Cordova training : Day 4 - Advanced Javascript
PPTX
Chapter 14 Dictionary.pptx
PPTX
Qtp training session IV
PDF
It Is Possible to Do Object-Oriented Programming in Java
PPT
JavaScript Workshop
PDF
Introduction to js (cnt.)
PPTX
PPTX
descriptive programming
PYTHON OBJECTS - Copy.pptx
Untitled dictionary in python program .pdf.pptx
Javascript Objects Deep Dive
Java: Objects and Object References
Persistence And Documents
Eqela Core API and Utilities
python full notes data types string and tuple
Comparable/ Comparator
Functional Core, Reactive Shell
JavaScript Programming
Object oriented database concepts
Cordova training : Day 4 - Advanced Javascript
Chapter 14 Dictionary.pptx
Qtp training session IV
It Is Possible to Do Object-Oriented Programming in Java
JavaScript Workshop
Introduction to js (cnt.)
Ad

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Yogi Goddess Pres Conference Studio Updates
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Lesson notes of climatology university.
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharma ospi slides which help in ospi learning
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Yogi Goddess Pres Conference Studio Updates
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
O7-L3 Supply Chain Operations - ICLT Program
Lesson notes of climatology university.
Orientation - ARALprogram of Deped to the Parents.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Complications of Minimal Access Surgery at WLH
Pharma ospi slides which help in ospi learning
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
human mycosis Human fungal infections are called human mycosis..pptx
Microbial disease of the cardiovascular and lymphatic systems
Supply Chain Operations Speaking Notes -ICLT Program
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O5-L3 Freight Transport Ops (International) V1.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS

Basics of dictionary object

  • 1. Dictionary Object In QTP : The Dictionary object is used to hold a set of data values in the form of (key, item) pairs. It is also known as 'Associative Array' because it associates a key with an item. If you compare it with an Array, Keys are similar to the indices in an array. But here Keys are not numetic Indices like we have in array ranther than these are arbitrary strings normally. Each key in a single Dictionary object must be unique. Dictionary Object is a part of VB Script and so it can be used with the tools supporting VBS. (Here we will talk how it used in QTP). Dictionary object is COM object(Component Object Model) and “Scripting.Dictionary” is the ProdID for Disctionary object. It can be instantiated as following: Dim oDict Set oDict = CreateObject("Scripting.Dictionary") Using Add method we can add fdifferent keya and pair values to the structure. Set oDict = CreateObject("Scripting.Dictionary") oDict.Add "Tool1", "Selenium" oDict.Add "Tool2", "QTP" oDict.Add "Tool3", "Silk Test" Then it should look like Key Value Tool1 Selenium Tool2 QTP Tool3 Silk Test To fetch the data from the Dict object we can use .Item method. Msgbox oDict.item("Tool2") -- Should return respective item value i.e QTP The problem with Dictionary object is, if you try to access any item which is not even present in the Dictionary,it does not result in an error. Instead, the non-existent element is added to the Dictionaty object. Set oDict = CreateObject("Scripting.Dictionary") oDict.Add "Tool1", "Selenium" oDict.Add "Tool2", "QTP" oDict.Add "Tool3", "Silk Test" MsgBox oDict.Item("Tool4")
  • 2. Here no ArrayIndexOutOfBoundsException occurs, rather than Tool4, is added to the Dictionary, along with the item value Null. Looping through the Items in Dictionary Object: Dim oItem Dim sItem, sMsg Dim oDict Set oDict = CreateObject("Scripting.Dictionary") Set oDict = CreateObject("Scripting.Dictionary") oDict.Add "Tool1", "Selenium" oDict.Add "Tool2", "QTP" oDict.Add "Tool3", "Silk Test" For Each oItem In oDict sItem = oDict.Item(oItem ) sMsg = sMsg & sItem & vbCrLf Next MsgBox sMsg Dictionry object having only one configurable property, Compare Mode. If its is created in binary mode, which means each key in the Dictionary is based on its ASCII value. Means lowercase and upper cases are treated as different here. When a Dictionary is configured in text mode, uppercase and lowercase letters are treated identically. 0 – Sets the mode to binary. This is the default value. 1 – Sets the mode to text. Set oDict = CreateObject("Scripting.Dictionary") oDict.CompareMode = 1 Initially while creating only youi can set the compare mode.Once it is alreday having any element, you are not allowed to change the compare mode. To reconfigure the Dictionary mode, you first need to remove all items from the Dictionary. To remove a value from a dictionary, use the .Remove method and specify the key to remove. For example: oDict.Remove “Tool2" To remove all values and clear the dictionary, use the .RemoveAll method. Use the .Count property to obtain a count of values in the dictionary.
  • 3. The .Keys and .Items methods return an array containing all the keys or items from the dictionary. For example: aTools = oDict.Keys aNames = oDict.Items