Inspection Details

UnassignedVariableUsage


Summary
Warns when a variable is referenced prior to being assigned.
Reasoning
An uninitialized variable is being read, but since it's never assigned, the only value ever read would be the data type's default initial value. Reading a variable that was never written to in any code path (especially if Option Explicit isn't specified), is likely to be a bug.
The following code example(s) would trigger this inspection:

Public Sub DoSomething()
    Dim i As Long
    Debug.Print i ' i was never assigned
End Sub

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

Public Sub DoSomething()
    Dim i As Long
    i = 42
    Debug.Print i
End Sub


Back to List