Implicit ByRef Modifier

Highlights implicit ByRef modifiers in user code.

Reasoning

VBA parameters are implicitly ByRef, which differs from modern VB (VB.NET) and most other programming languages which are implicitly ByVal. So, explicitly identifying VBA parameter mechanisms (the ByRef and ByVal modifiers) can help surface potentially unexpected language results. The inspection does not flag an implicit parameter mechanism for the last parameter of Property mutators (Let or Set). VBA applies a ByVal parameter mechanism to the last parameter in the absence (or presence!) of a modifier. Exception: UserDefinedType parameters must always be passed as ByRef.

Default severity

Hint

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething(foo As Long) foo = 42 End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByRef foo As Long) foo = 42 End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Private theLength As Long Public Property Let Length(newLength As Long) theLength = newLength End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.ImplicitByRefModifierInspection.cs (Prerelease-v2.5.9.6289)