Inspection Details
ParameterCanBeByVal
- Summary
- Flags parameters that are passed by reference (ByRef), but could be passed by value (ByVal).
- Reasoning
- Explicitly specifying a ByVal modifier on a parameter makes the intent explicit: this parameter is not meant to be assigned. In contrast,
a parameter that is passed by reference (implicitly, or explicitly ByRef) makes it ambiguous from the calling code's standpoint, whether the
procedure might re-assign these ByRef values and introduce a bug.
- The following code example(s) would trigger this inspection:
-
Public Sub DoSomething(ByVal foo As Long, bar As Long)
Debug.Print foo, bar
End Sub
- The following code example(s) would not trigger this inspection:
-
Option Explicit
Public Sub DoSomething(ByVal foo As long, ByRef bar As Long)
bar = foo * 2
Debug.Print foo, bar
End Sub
Back to List