多参数子 vba

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10152306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:57:05  来源:igfitidea点击:

multiple argument subs vba

vbaargumentscall

提问by user1302398

Using VBA with Access 2010, I have a sub:

在 Access 2010 中使用 VBA,我有一个子项:

Public Sub setInterest(account As String, dmonth As Integer)
    ...somecode...
End Sub

And I am calling it with

我用

setInterest("myAccount",3)

And I get syntax errors.
Modifying the sub to only take one argument and leaving out the 3 gives no errors, the problem is only when I have 2 arguments.

我收到语法错误。
将 sub 修改为仅采用一个参数并省略 3 不会出错,只有当我有 2 个参数时才会出现问题。

回答by assylias

When using multiple arguments, you can either write:

使用多个参数时,您可以编写:

 setInterest "myAccount", 3

Or

或者

 Call setInterest("myAccount", 3)

In both examples you can name the arguments:

在这两个示例中,您都可以命名参数:

setInterest account:="myAccount", dmonth:= 3

回答by shA.t

I add this answer, for Why your syntax works with one argument ?

我添加了这个答案,因为为什么你的语法适用于一个参数?

Public Sub setInterest(account As String)
    '...somecode...
End Sub

setInterest ("myAccount")

Note :
When there is not any ,between (and ), VBA thinks it's a formulaand exactly one argument.

注意:
当and,之间没有任何值时,VBA 认为它是一个公式并且恰好是一个参数。()

When formula calculate the result will be like this:

当公式计算结果将是这样的:

Dim str As String
str = ("TEST")
Debug.Print str

[Output:]
TEST