Header Ads

Dictionary Object A fantastic Approach to solve Key Value Pair in QTP


Dictionary Object:
This is equivalent if a PERL associative array. Items /eliments can be any form of data  and are stored in the array. Each item is having an unique key. The key is used to retrived the detailed information
Exception:
It can store all possible values--string,integer,etc but can not store an array.
Where it can be used:
This is an unique coding technique where the fields are getting changed but the total no of fileds are given.The editbox sequence is dynamic.They may appear without any order.
The following code illustrates how to create a Dictionary object:
'............................Create a Dictionary..............................................

Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"

'..........................How to compare.....................................................
d.CompareMode = vbTextCompare

'..........................Checking the key ..Exist Method.............................

If d.Exists("c") Then
msg = "Specified key exists."
Else
msg = "Specified key doesn't exist."
End If
KeyExistsDemo = msg

'.......................Key method.................................................................

a = d.Items ' Get the items.
For i = 0 To d.Count -1 ' Iterate the array.
s = s & a(i) & "
" ' Create return string.
Next
DicDemo = s

'........................Remove item.................................................................

d.Remove("b") ' Remove second pair.
a = d.RemoveAll ' Clear the dictionary.

'.......................





Powered by Blogger.