Inspection Details

OptionBase


Summary
Flags modules that specify Option Base 1.
Reasoning
Implicit array lower bound is 0 by default, and Option Base 1 makes it 1. While compelling in a 1-based environment like the Excel object model, having an implicit lower bound of 1 for implicitly-sized user arrays does not change the fact that arrays are always better off with explicit boundaries. Because 0 is always the lower array bound in many other programming languages, this option may trip a reader/maintainer with a different background.
The following code example(s) would trigger this inspection:

Option Explicit
Option Base 1
Public Sub DoSomething()
    Dim foo(10) As Long ' implicit lower bound is 1, array has 10 items.
    ' ...
End Sub

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

Option Explicit
Public Sub DoSomething()
    Dim foo(10) As Long ' implicit lower bound is 0, array has 11 items.
    Dim bar(1 To 10) As Long ' explicit lower bound removes all ambiguities, Option Base is redundant.
    ' ...
End Sub


Back to List