【问题标题】:multiple argument subs vba多参数 subs vba
【发布时间】:2012-04-26 11:52:48
【问题描述】:

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

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

我用它来称呼它

setInterest("myAccount",3)

我遇到语法错误。
将 sub 修改为仅接受一个参数并省略 3 不会出错,问题仅在于我有 2 个参数时。

【问题讨论】:

标签: vba arguments call


【解决方案1】:

当使用多个参数时,您可以这样写:

 setInterest "myAccount", 3

或者

 Call setInterest("myAccount", 3)

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

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

【讨论】:

    【解决方案2】:

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

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

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

    公式计算的时候结果是这样的:

    Dim str As String
    str = ("TEST")
    Debug.Print str
    
    [Output:]
    TEST
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多