Pages

Friday, March 30

Find distinct unique values from array using QTP/vbscript

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...