L33*_*EAN 6 vbscript automated-tests qtp
我无法让我的测试用例正确运行.
问题在于下面的代码,第一个if语句是准确的.QTP抱怨需要一个对象
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
当我检查数组时,我可以看到它被正确填充,'j'也是正确的字符串.任何有关此问题的帮助将不胜感激.
Mot*_*tti 16
VBScript中的字符串不是对象,因为它们没有成员函数.应该使用该InStr函数来搜索子字符串.
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
gbo*_*tti 15
检查字符串数组是否包含值的简明方法是组合Filter和UBound函数:
If Ubound(Filter(options, choice)) > -1 Then
    MsgBox "Found"
Else
    MsgBox "Not found!"
End If
缺点:您没有获得找到元素的索引
优点:它很简单,您可以使用通常的包含和比较参数来指定匹配条件.