Inspection Details

AssignedByValParameter


Summary
Warns about parameters passed by value being assigned a new value in the body of a procedure.
Reasoning
Debugging is easier if the procedure's initial state is preserved and accessible anywhere within its scope. Mutating the inputs destroys the initial state, and makes the intent ambiguous: if the calling code is meant to be able to access the modified values, then the parameter should be passed ByRef; the ByVal modifier might be a bug.
The following code example(s) would trigger this inspection:

Public Sub DoSomething(ByVal foo As Long)
    foo = foo + 1 ' is the caller supposed to see the updated value?
    Debug.Print foo
End Sub

The following code example(s) would not trigger this inspection:

Public Sub DoSomething(ByVal foo As Long)
    Dim bar As Long
    bar = foo
    bar = bar + 1 ' clearly a local copy of the original value.
    Debug.Print bar
End Sub


Back to List