VBA语法中括号的使用

不同语言函数调用的语法有不同的,比如C++函数调用要加括号的,但是在VB中加不加括号要视情况而定,该不加的地方加了也是语法错误。

以下是来自VBA帮助中的原话:

The syntax for functions and some methods shows the arguments enclosed in parentheses. These functions and methods return values, so you must enclose the arguments in parentheses to assign the value to a variable. If you ignore the return value or if you don't pass arguments at all, don't include the parentheses. Methods that don't return values do not need their arguments enclosed in parentheses. These guidelines apply whether you're using positional arguments or named arguments.

另外一篇帮助文件:

Sub procedures, built-in statements, and some methods don't return a value, so the arguments aren't enclosed in parentheses. For example:

MySub "stringArgument", integerArgument

Function procedures, built-in functions, and some methods do return a value, but you can ignore it. If you ignore the return value, don’t include parentheses. Call the function just as you would call a Sub procedure. Omit the parentheses, list any arguments , and don't assign the function to a variable. For example:

MsgBox "Task Completed!", 0, "Task Box"

To use the return value of a function, enclose the arguments in parentheses。

总结一下:用到返回值,加括号;没用到返回值,不要加括号。函数或方法的语法里有括号,表示它有返回值,但是在语句里如果不利用这个返回值赋给变量的话,调用函数或方法不要加括号。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值