Sunday 2 February 2014

How to get distinct value from an array

In this post, we will check, 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
Array1 = Array ("101", "201", "101", "301", "201", "401", "301")


Set objDict = CreateObject("Scripting.Dictionary")
objDict
.CompareMode = vbTextCompare

For each val in Array1
objDict
(val) = val
Next

Array2 = 
objDict.Items

For i=0 to ubound(Array2)
msgbox
 Array2(i)
Next 

No comments:

Post a Comment