Compile Error “Expected: =” when calling another procedure

大憨熊 提交于 2021-02-05 06:46:06

问题


I try to call a procedure giving to arguments, it throws a compile error stating "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
__________________________________________

It fails when I insert the call " Call_01_Adj_Report(div, isWorkaround)". It works when giving only one Parameter, but not for two. But in my understanding, the procedure call with arguments syntax is right. What might be the problem?


回答1:


Your procedure call syntax is not right.

This: Call_01_Adj_Report(div, isWorkaround)

Needs to be: Call_01_Adj_Report div, isWorkaround

Or, with the obsolete explicit call syntax: Call Call_01_Adj_Report(div, isWorkaround)

I normally dislike explicit call syntax quite much, but here I like how it highlights how weird the procedure name is. Avoid underscores in public members (should be PascalCase), and start procedure names with a verb, e.g. CreateAdjustmentsReport:

CreateAdjustmentsReport div, isWorkaround



回答2:


If you want to maintain parenthesis for calling a sub:

use Call keyword

Call Call_01_Adj_Report(div, isWorkaround)

Similarly if you declare a function that returns value (not sub), you can call the function with parenthesis without using "Call"

example:

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

Public Sub test()
    func (10)
End Sub


来源:https://stackoverflow.com/questions/43809959/compile-error-expected-when-calling-another-procedure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!