Difference between dictionary and array in QTP

The below comparison provides how we could use array and dictionary in UFT/QTP functional tool.

Difference between dictionary and array in QTP
Difference between dictionary and array in QTP

Array:

1.An array is a like container object which holds a fixed number of values of a single type.
2.Arrays can be dynamic in qtp or any other programming ex: Redim to change the array size
3.Before using an array we must declare the size of a array.
4.If we want to increase the array size in script we have to use Redim statement to increase the array.
5.QTP does not have any method to release the memory in case any element is not requried.

Dictionary:

Dictionary object has many builtin functions which can add, remove, access the elements using unique key. 

1.QTP does not have any concept like dynamic Dictionary
2.No need to set size of the dictionary in QTP
3.Not required to use any statement to add extra element,just use add method.
4.Can remove elements which is no longer useful.

Ex:
Dim dict ' Create a variable.
Set dict = CreateObject("Scripting.Dictionary")
dict.Add "QTP", "HP" ' Adding keys and corresponding items.
dict.Add "Functional Tool", "UFT"

Other methods available for dictionary object are Exists Method, Items Method, Keys Method, Remove Method, RemoveAll Method.

Post a Comment

0 Comments