Micro Focus QTP (UFT) Forums
Is a value in an array - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Is a value in an array (/Thread-Is-a-value-in-an-array)



Is a value in an array - Brian.Osborne - 02-17-2011

I have a simple array I've defined.
I'm pulling a value into my datatable as a seperate action to use later.
Now I need to check my array and execute a line of code ONLY if the value I put into my datatable is present in the array.

Code:
TestArray = Array("value1", "value2")

TeWindow....TeField("FieldName").Output CheckPoint("GetValue")

If DataTable("GotValue", dtGlobalSheet) 'help me'  Then
...This code will execute if "GotValue" is in the TestArray
End If



RE: Is a value in an array - surya_7mar - 02-17-2011

Code:
Function ArrayFind(arrToSearch,strToFind)
        Dim aIter
        For aIter=0 To UBound(arrToSearch)
            If Replace(Trim(arrToSearch(aIter)), chr(32), chr(160))=Replace( Trim(strToFind), chr(32), chr(160)) Then
                ArrayFind=aIter+1
                Exit Function
            End If
        Next
        ArrayFind=-1
    End Function

If ArrayFind(TestArray ,DataTable("GotValue", dtGlobalSheet)) <> -1 'help me' Then
...This code will execute if "GotValue" is in the TestArray
End If



RE: Is a value in an array - tarun - 02-17-2011

Suggest you to use a collection instead of an array


RE: Is a value in an array - basanth27 - 02-23-2011

Worth a try.. Think about it,
Join the array using the join keyword and then use the instr function to check if the string exist.