问题
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