07 November 2017

Difference between Array and Dictionary Object in UFT

1. Dictionary cannot be multidimensional, while an array can be multidimensional
2. QTP does not have any concept like dynamic Dictionary, but Array can be Dynamic
3. When we delete one particular item from the dictionary, all subsequent item automatically shift up.
4. Array can have index only as numeric (0,1,2..) while we can  use keys to identify dictionary items and Keys can be of any data subtype(String, integer)
5. No need to set the size of the dictionary object in QTP, while initializing an Array is must. And If we want to increase the array size in script we can use Redim and Redim Preserve statement to increase the array.
6. Various methods available for dictionary object like Exists, Items, Keys, Remove, RemoveAll
7. QTP does not have any method to release the memory in case any element is not required, while in Dictionary object we can delete any element if it is not required

Example:

'Declaring array 
Dim arr()
'Resizing Array
ReDim arr(2)
arr(0) = "UFT14"
arr(1) = "QTP11"
arr(2) = "QTP10"

msgbox arr(0)   'Returns UFT14


'Creating Dictionary Object
Set obj = createobject("scripting.dictionary")
'Using Add methods to add values to dictionary object
obj.Add"UFT14","Version 14"
obj.Add"QTP11","Version 11"
obj.Add"QTP10","Version 10"

'Locating items in Dictonary
MsgBox obj.item("UFT14")   'Returns Version 14


....

No comments:

Post a Comment

AOM - Automation Object Model

'Creating QuicTest Object Set  qtapp =  createobject ( "QuickTest.Application" ) 'Launching the Application If  qtapp...