Hello Friends,
In this post, we will see, how to get unique/distinct values from an array.
We will do that using very useful and optimum feature of QTP – Dictionary Object.
Here is the code–
Dim objDict, oldArray, val
oldArray = Array (“11”, “21”, “11”, “31”, “21”, “41”, “31”)
Set objDict = CreateObject(“Scripting.Dictionary”)
objDict.CompareMode = vbTextCompare
For each val in oldArray
objDict(val) = val
Next
newArray = objDict.Items
For i=0 to ubound(newArray)
msgbox newArray(i)
Next
…n done!!!
Plz do post your queries/comments…
Nice Code. It is reaching our expectations without any updates
Hi,
Need small change in below part of above mentioned code…
Incorrect One :
For i=0 to ubound(newArray)
msgbox newArray(i)
Next
Correct One :
For i=0 to ubound(newArray)-1
msgbox newArray(i)
Next