491623644 发表于 2013-7-4 14:48:22

【已解决】QTP编程时,什么时候使用括号,什么时候不使用括号?

本帖最后由 491623644 于 2013-7-5 09:50 编辑

set oWsh=createobject("wscript.shell")
oWsh.Run "notepad"
oWsh.AppActivate "无标题 - 记事本"
oWsh.SendKeys"Pavel"
oWsh.AppActivate "无标题 - 记事本" 是需不需要带括号呢?在什么情况下带括号呢?

TEST_HUAN 发表于 2013-7-4 16:07:52

不用纠结这个吧,具体查帮助
一般带括号是函数,不带是sub

491623644 发表于 2013-7-4 16:25:25

回复 2# TEST_HUAN

set oWsh=createobject("wscript.shell")
oWsh.Run "notepad"
While not oWsh.AppActivate "无标题 - 记事本"
wend
oWsh.SendKeys"Pavel"

为什么我在执行上面的语句的时候,会出现错误
如果加上括号
While not oWsh.AppActivate ("无标题 - 记事本")
就不会出错了呢?

帮助上面是没有加括号的

TEST_HUAN 发表于 2013-7-4 17:27:46

不会吧,等一下我测试以下

云层 发表于 2013-7-4 17:50:49

如果我没记错应该是有返回的是带()没返回的不带!!

如果不对反过来

TEST_HUAN 发表于 2013-7-5 09:03:45

因为有while语句,需要用括号
Remarks
The AppActivate method returns a Boolean value that identifies whether the procedure call is successful. This method changes the focus to the named application or window, but it does not affect whether it is maximized or minimized. Focus moves from the activated application window when the user takes action to change the focus (or closes the window).

In determining which application to activate, the specified title is compared to the title string of each running application. If no exact match exists, any application whose title string begins with title is activated. If an application still cannot be found, any application whose title string ends with title is activated. If more than one instance of the application named by title exists, one instance is arbitrarily activated.

491623644 发表于 2013-7-5 09:50:15

谢谢!

kavensyw 发表于 2013-7-6 09:55:03

本帖最后由 kavensyw 于 2013-7-6 09:57 编辑

记住一点就行了:有=号(赋值)的加括号,没=号的就不用加括号。即使函数有返回值但不赋给别的变量好像也不用加括号。
    按我的理解好像是这样。
页: [1]
查看完整版本: 【已解决】QTP编程时,什么时候使用括号,什么时候不使用括号?