Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Inspection for redundant variable initializations

Open retailcoder opened this issue 8 years ago • 1 comments

If a variable's first assignment (taking code paths into account) is a literal with the default value for that variable's declared type, Rubberduck should suggest removing that redundant assignment.

    Dim foo As String
    foo = vbNullString ' or ""

    Dim foo As Integer ' or any numeric type actually
    foo = 0

    Dim foo As Boolean
    foo = False

    Dim foo As Object ' or any reference type
    Set foo = Nothing

    Dim foo As Date
    foo = 0 ' 1899-12-30 12:00:00AM actually, so #1899-12-30#

    Dim foo As Variant
    foo = Empty ' vbEmpty still makes "(foo = vbEmpty)" evaluate to True, but converts to 0

retailcoder avatar Feb 23 '17 20:02 retailcoder