Right Click Disabled

Sunday, February 26, 2012

VBScript code in QTP to create a dictionary object to access a dictionary, to store five pairs of data into that dictionary and then to find total marks stored in that dictionary.

Option explicit
Dim dico, i, sn, m, lm, tot
'Here     i       for loop
'            sn     for subject name
'            m     for marks
'            lm    for list of marks
'            tot   for total
'Create dictionary object and add pairs of data
Set dico=CreateObject("Scripting.Dictionary")
For i=1 to 5 step 1
      sn=inputbox("Enter Subject Name : ")
      m=inputbox("Enter Marks : ")
      dico.Add sn,m
Next
'Find total marks in that dictionary
tot=0
lm=dico.Items
For each m in lm
      tot=tot+m
Next
Print("Total Marks is :"&tot)
Set dico=nothing

Thursday, February 23, 2012

Dictionary Object


Dictionary is used to store pairs of data and every pair first value is called as Key and second value is called as Item. To access this dictionary pairs we can use an object called as dictionary object.



The corresponding dictionary object can create an interface between QTP tool and a dictionary in memory (RAM). To create dictionary object and access dictionary content using that object, we can use below code in VBScript in QTP tool:

Option explicit
Dim dico
Set dico=CreateObject("Scripting.Dictionary")

In the above code createobject() function is used to create an object for specified data structure. Here “dico” is an object for a dictionary.

To store data into dictionary as pairs, dictionary object is providing a function or method like shown below:

Option explicit
Dim dico
Set dico=CreateObject("Scripting.Dictionary")
dico.Add "English", 78
dico.Add "Hindi", 65
dico.Add "Maths", 98
dico.Add "Computers", 90
dico.Add "Physics", 80

While adding pairs of data to dictionary using dictionary object, corresponding test automater can maintain unique values for Keys.

VBScript code in QTP for to display addition of two arrays


Option explicit
Dim array1(4), array2(4), array3(4), i
For i=0 to 4 step 1
      array1(i)=inputbox("Enter value for Array 1 :")
Next
For i=0 to 4 step 1
      array2(i)=inputbox("Enter value for Array 2 :")
Next
For i=0 to 4 step 1
      array3(i)=cint(array1(i))+cint(array2(i))
      print(array3(i))
Next
Twitter Bird Gadget