Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTP: Checking If an array of strings contains a value

I am having trouble getting my test case to run correctly.

The problem is in the code below, the first if statement to be exact. QTP complains that an object is required

For j=Lbound(options) to Ubound(options)
    If options(j).Contains(choice) Then
        MsgBox("Found " & FindThisString & " at index " & _
        options.IndexOf(choice))
    Else
        MsgBox "String not found!"
    End If
Next

When I check the array I can see that it is populated correctly and 'j' is also the correct string. Any help with this issue would be greatly appreciated.

like image 416
Daniel Flannery Avatar asked Aug 09 '12 08:08

Daniel Flannery


People also ask

How do you check if an array contains a value?

The includes() method returns true if an array contains a specified value. The includes() method returns false if the value is not found.

How do you check if a string is present in an array or not?

You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't exist.

How do you check if an array contains a value in TypeScript?

Use the includes() method to check if an array contains a value in TypeScript, e.g. if (arr. includes('two')) {} . The includes method will return true if the value is contained in the array and false otherwise.


1 Answers

Strings in VBScript are not objects, in that they do not have member functions. Searching for a substring should be done by using the InStr function.

For j=Lbound(options) to Ubound(options)
    If InStr(options(j), choice) <> 0 Then
        MsgBox("Found " & choice & " at index " & j
    Else
        MsgBox "String not found!"
    End If
Next
like image 145
Motti Avatar answered Sep 24 '22 23:09

Motti