Function RegExpCheck(string1,string2) 'expch正则表达式符号,string1被搜索的字符串,string2在其上搜索的字符串
Dim regEx, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = string1 ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(string2) ' Execute search.
If (Matches.count=0) Then
msgbox("false")
Else
msgbox("true")
End If
End Function
set temp=browser("工程项目管理信息系统").Page("工程项目管理信息系统_4").Frame("frm_right_2").WebEdit("WebEdit").GetROProperty("value")
testcode="^"&testcode ’加入^元字符
RegExpCheck (testcode,temp) '调用自定义函数,从temp中找testcode
结果报错,说什么”调用子程序时不能使用括号?“
这是啥意思?望高手指点一下作者: henhenchen 时间: 2007-4-10 23:46 标题: 我觉的你的CODE 有点问题.1 FUNCTION 应有RETURN 值.要是没有.最好定义SUB 2 .什么地方要用括号给你PASTE 一段QTP USER GUILDE 的内容:
Using Parentheses
You must use parentheses around method arguments if you are calling a
method that returns a value and you are using the return value.
For example, use parentheses around method arguments if you are
returning a value to a variable, if you are using the method in an If
statement, or if you are using the Call keyword to call an action or function.
You also need to add parentheses around the name of a checkpoint if you
want to retrieve its return value
The following example requires parentheses
Set WebEditObj = Browser("Mercury Tours").Page("Method of Payment").
WebTable("FirstName").ChildItem (8, 2, "WebEdit", 0)
WebEditObj.Set "Example"
Call RunAction("BookFlight", oneIteration)
or
Call MyFunction("Hello World")
because the method is used in an If statement.
If Browser("index").Page("index").Link("All kind of").
WaitProperty("attribute/readyState", "complete", 4) Then
Browser("index").Page("index").Link("All kind of").Click
End If
NO Parentheses
Browser("Mercury Tours").Page("Method of Payment").WebTable("FirstName").
Click 3,4
The following example requires parentheses around the
It u want to check whether text box is visible or not
If Browser("TEST").Page("TEST").WebEdit("FirstEditBox").GetROProperty("visible") = TRUE Then
Reporter.ReportEvent 0, "pass", "pass"
Else
Reporter.ReportEvent 1, "fail", "fail"
End If作者: walker1020 时间: 2007-4-11 11:30
根据错误提示,把 RegExpCheck (testcode,temp) 改为 RegExpCheck testcode,temp 后试试看看。作者: walker1020 时间: 2007-4-11 11:32
另外,testcode="^"&testcode 应该为 testcode="^"&test 吧? 因为前面压根就没有testcode 这个变量的定义,而只有test 这个变量的定义。作者: firefox82 时间: 2007-4-11 14:21
感觉不是括号的问题。。我写的脚本中也是用括号的
"FUNCTION 应有RETURN 值.要是没有.最好定义SUB"引用上面的话作者: kursk 时间: 2007-4-11 14:24
谢谢大家,我已经解决了问题,特此作个总结
function 返回值和调用时使用()的问题
例子1,下面的例子里function没有返回值
function RegExpCheck(string1,string2) 'expch正则表达式符号,string1被搜索的字符串,string2在其上搜索的字符串
Dim regEx, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = string1 ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(string2) ' Execute search.
If (Matches.count=0) Then
msgbox("没找到")
Else
msgbox( "找到了")
End If
End function
function RegExpCheck(string1,string2) 'expch正则表达式符号,string1被搜索的字符串,string2在其上搜索的字符串
Dim regEx, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = string1 ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(string2) ' Execute search.
If (Matches.count=0) Then
RegExpCheck="没找到"
Else
RegExpCheck= "找到了"
End If
End function