Assignment Not Used

Warns about a local variable that is assigned and never read. Or, warns about a local variable that is assigned and then re-assigned before using the previous value.

Reasoning

An assignment that is never used is a meaningless statement that was likely used by an execution path in a prior version of the module.

Default severity

Suggestion

Inspection type

CodeQualityIssues

Examples

This example should trigger a result

Module1 (StandardModule)
Public Sub DoSomething(ByRef value As Long) Dim localVar As Long localVar = 12 ' assignment never used Dim otherVar As Long otherVar = 12 value = otherVar * value End Sub

This example should trigger a result

Module1 (StandardModule)
Public Sub DoSomething() Dim localVar As Long localVar = 12 ' assignment is redundant localVar = 34 End Sub

This example should NOT trigger a result

Module1 (StandardModule)
Public Function DoSomething(ByVal value As Long) As Long Dim localVar As Long localVar = 12 localVar = localVar + value 'variable is re-assigned, but the prior assigned value is read at least once first. DoSomething = localVar End Function

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