我使用Access 2010和VBA编写了一个子程序:
Public Sub setInterest(account As String, dmonth As Integer)
...somecode...
End Sub
我正在使用以下方式调用它:
setInterest("myAccount",3)
我遇到了语法错误。
将这个子程序修改为只接受一个参数且忽略掉第三个参数时不会出现错误,问题只出现在有两个参数的情况下。
我使用Access 2010和VBA编写了一个子程序:
Public Sub setInterest(account As String, dmonth As Integer)
...somecode...
End Sub
我正在使用以下方式调用它:
setInterest("myAccount",3)
我遇到了语法错误。
将这个子程序修改为只接受一个参数且忽略掉第三个参数时不会出现错误,问题只出现在有两个参数的情况下。
当使用多个参数时,你可以写成:
setInterest "myAccount", 3
或者 Call setInterest("myAccount", 3)
在这两个例子中,你可以给参数命名:
setInterest account:="myAccount", dmonth:= 3
我添加了这个答案,来回答为什么你的语法只需要一个参数就可以工作?
Public Sub setInterest(account As String)
'...somecode...
End Sub
setInterest ("myAccount")
注意:
当在(
和)
之间没有任何,
时,VBA会认为它是一个公式并且只有一个参数。
当公式计算结果如下:
Dim str As String
str = ("TEST")
Debug.Print str
[Output:]
TEST