Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Summary

Forces all variables used to be defined and properly typed. VB is not strongly typed so it's kinda of easy to get "spaghetti" code going. This helps to cut down on it. Also helps the user instantly find typos in variable names.

Syntax

Option Base [0|1]

-or-

Option Compare [Binary | Text]

...

-or-

Option Private Module

Description

Form 1: Set the default base index for array declarations. Affects Dim, Static, Private, Public and ReDim. Does not affect Array, ParamArray or arrays declare in a Type. Option Base 0 is the default.

...

Form 4: Public symbols defined by the module are only accessible from the same project.

Example

Option Base 1
Option Explicit

Sub Main
    Dim A
        Dim C(2) ' same as Dim C(1 To 2)
        Dim D(0 To 2)
    A = 1
    B = 2 ' B has not been declared
End Sub