调用另一个程序时编译错误“Expected:=”

时间:2017-05-05 16:39:56

标签: vba

我尝试调用一个给出参数的过程,它抛出一个编译错误,声明“Expected:=”。

...

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)”时失败。 只给出一个参数,但不给两个参数,它可以工作。但在我的理解中,带参数语法的过程调用是正确的。可能是什么问题?

2 个答案:

答案 0 :(得分:4)

您的过程调用语法正确。

这:Call_01_Adj_Report(div, isWorkaround)

需要:Call_01_Adj_Report div, isWorkaround

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

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

CreateAdjustmentsReport div, isWorkaround

答案 1 :(得分:0)

如果要保留用于调用sub的括号:

使用Call关键字

Call Call_01_Adj_Report(div, isWorkaround)

同样,如果声明一个返回值(而不是sub)的函数,则可以使用括号调用该函数,而不使用" Call"

示例:

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

Public Sub test()
    func (10)
End Sub