【问题标题】:Compile Error "Expected: =" when calling another procedure调用另一个过程时编译错误“预期:=”
【发布时间】:2017-09-22 02:19:45
【问题描述】:

我尝试调用一个提供参数的过程,它会抛出一个编译错误,说明“预期:=”。

...

Dim isWorkaround As Boolean
isWorkaround = False
If Check101.Value = True Then
     isWorkaround = True
End If

...

'Procedure I try to call
ElseIf Combo_Report_Selection = "Adjusted Report" And Combo_someOther= "Other" Then
   Call_01_Adj_Report(div, isWorkaround)
ElseIf Combo_Report_Selection = "Upload Log" Then
   Call_03_Upload_Log
ElseIf Combo_Report_Selection = "Gather Summary" Then
   Call_04_Adj_Summary
End If

Combo_Report_Selection.Value = Null
Combo_Statement.Value = Null

End Sub
__________________________________________

Private Sub Call_01_Adj_Report(ByRef calldiv As Long, ByRef isWorkaround As Boolean)

...

End Sub
__________________________________________

当我插入调用“​​Call_01_Adj_Report(div,isWorkaround)”时它失败了。 它仅在提供一个参数时有效,但不适用于两个参数。但据我了解,带参数语法的过程调用是正确的。可能是什么问题?

【问题讨论】:

  • 请参阅this is confusing, why not just always use parentheses? 以了解为什么需要删除那里的括号。您的过程调用语法正确。
  • @MathieuGuindon 链接现已断开,因为 Stackoverflow 已关闭“文档”
  • @Trashman 那内容也可以在 SO 上找到here,而 RIP 教程有原始的 SO Doc 文章 here

标签: vba


【解决方案1】:

您的过程调用语法正确。

这个:Call_01_Adj_Report(div, isWorkaround)

需要是:Call_01_Adj_Report div, isWorkaround

或者,使用过时的显式调用语法:Call Call_01_Adj_Report(div, isWorkaround)

我通常非常不喜欢 显式调用 语法,但在这里我喜欢它如何突出过程名称的怪异。避免在公共成员中使用下划线(应为PascalCase),并以动词开头,例如CreateAdjustmentsReport:

CreateAdjustmentsReport div, isWorkaround

【讨论】:

    【解决方案2】:

    如果您想保留括号以调用sub

    使用Call关键字

    Call Call_01_Adj_Report(div, isWorkaround)
    

    同样如果你声明一个返回值(不是子)的函数,你可以不使用“调用”来调用带括号的函数

    示例:

    Public Function func(ByVal variable As Integer)
      variable = variable + 100
    End Function
    
    Public Sub test()
        func (10)
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      相关资源
      最近更新 更多