Option Base

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.

Default severity

Hint

Inspection type

NamingAndConventionsIssues

Examples

This example should trigger a result

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

This example should NOT trigger a result

MyModule (StandardModule)
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

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