我想在VB6中将int
转换为string
并将string
解析为Instr
函数,但我无法做到这一点,这是我的代码:< / p>
'.WebElement("total_Count").GetROProperty("innertext")=1 - 10 de 31 candidatos
'This is the value in innertext, and i want to compare the 31
totalCount=31
CStr (totalCount)
If InStr(totalCount,.WebElement("total_Count").GetROProperty("innertext"))>0Then
MsgBox "Found"
Reporter.ReportEvent micPass,"DBVerification","TotalCount Verified From DB"
Else
MsgBox "Not Found"
Reporter.ReportEvent micFail,"DBVerification","TotalCount Not Verified From DB"
End If
感谢您的帮助
答案 0 :(得分:1)
VB6上的比较区分大小写,除非在模块/表单/类的顶部使用Option Compare Text
;在这种特殊情况下,它无关紧要。此外,CStr(totalCount)
未分配任何内容,不会将TotalCount更改为字符串;它返回一个字符串。
totalCount=31
If InStr(lcase(CStr(totalCount)),lcase(.WebElement("total_Count").GetROProperty("innertext")))>0 Then
MsgBox "Found"
Reporter.ReportEvent micPass,"DBVerification","TotalCount Verified From DB"
Else
MsgBox "Not Found"
Reporter.ReportEvent micFail,"DBVerification","TotalCount Not Verified From DB"
End If
答案 1 :(得分:0)
为什么不将它们作为数字进行比较,就像你做的那样,如果totalcount = 31且innertext包含1,你将得到True,这肯定不是你想要的。
答案 2 :(得分:0)
交换Instr()函数的参数:
InStr(.WebElement("total_Count").GetROProperty("innertext"), totalCount)>0
现在您正在查看31是否在您的innertext中。您不必使用cStr()
,lCase()
或其他内容,VBScript会为您执行此操作。
编辑:你真正想让它正常工作的当然是正则表达式:
Dim regEx, matches, actualTotal
set regEx = new RegExp
regEx.Global = True
regEx.pattern = "\d+ - \d+ de (\d+) candidatos"
Set matches = regEx.Execute(Value)
actualTotal = matches(0).submatches(0)
现在,您可以将actualTotal与预期总数进行比较,如果数字在字符串的其余部分,则无需担心。 例如: “31 - 40 de 42 candidatos”将导致误报。使用RegExp可以防止这种行为。