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




Dictionary Object:
This is equivalent if a PERL associative array. Items /elements can be any form of data and are stored in the array. Each item is having a unique key. The key is used to retrieve 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 a unique coding technique where the fields are getting changed but the total no of fields are given. The edit box 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.
 
Dictionary Object A fantastic Approach to solve Key Value Pair in QTP Dictionary Object A fantastic Approach to solve Key Value Pair in QTP Reviewed by Animesh Chatterjee on December 14, 2008 Rating: 5

No comments:

Powered by Blogger.