# Option
{: .no_toc }

Configures a compiler option.

* TOC
{:toc}

## Option Base
{: #Base }

Syntax: **Option Base** { **0** \| **1** }

Used at the [module level](/tB/Gloss.md#module-level) to declare the default lower bound for array subscripts.

Because the default base is **0**, the **Option Base** statement is never required.

If used, the statement must appear in a [module](/tB/Gloss.md#module) or [class](/tB/Gloss.md#class) before any procedures, functions, or properties. **Option Base** can appear only once in a module and must precede array [declarations](/tB/Gloss.md#declaration) that include dimensions.

> [!NOTE]
> The **To** clause in the [**Dim**](/tB/Core/Dim.md), [**Private**](/tB/Core/Private.md), [**Public**](/tB/Core/Public.md), [**ReDim**](/tB/Core/ReDim.md), and [**Static**](/tB/Core/Static.md) statements provides a more flexible way to control the range of an array's subscripts. However, when the lower bound is not explicitly set with a **To** clause, **Option Base** can change the default lower bound to 1. The base of an array created with the [**ParamArray**](/tB/Core/ParamArray.md) keyword is zero; **Option Base** does not affect [**ParamArray**](/tB/Core/ParamArray.md) (or the [**Array**](/tB/Modules/Information/Array.md) function).

The **Option Base** statement only affects the lower bound of arrays in the module where the statement is located.

### See Also
{: .no_toc }

- [**Dim**](/tB/Core/Dim.md) and [**ReDim**](/tB/Core/ReDim.md) statements
- [**LBound**](/tB/Modules/Information/LBound.md) and [**UBound**](/tB/Modules/Information/UBound.md) functions

### Example of use at module level
{: .no_toc }

This example uses the **Option Base** statement to override the default base array subscript value of 0. The [**LBound**](/tB/Modules/Information/LBound.md) function returns the smallest available subscript for the indicated dimension of an array. The **Option Base** statement is used at the module level only.

```tb check_build
Module MyModule
    Option Base 1 ' Set the default array subscripts to 1. 
    Sub Example()
        Dim MyArray(20), TwoDArray(3, 4) ' Declare array variables. 
        Dim ZeroArray(0 To 5) ' Override the default base subscript. 

        ' Use LBound function to test lower bounds of arrays. 
        Debug.Print LBound(MyArray)      ' Prints 1. 
        Debug.Print LBound(TwoDArray, 2) ' Returns 1. 
        Debug.Print LBound(ZeroArray)    ' Returns 0. 
    End Sub
End Module
```

### Example of use at class level
{: .no_toc}

```tb check_build
Class Example1
    Option Base 1
    Sub New()
        Dim A1(5)
        Debug.Print LBound(A1)  ' Prints 1
    End Sub
End Class

Class Example0
    Option Base 0
    Sub New()
        Dim A0(5)
        Debug.Print LBound(A0)  ' Prints 0
    End Sub
End Class
```

## Option Explicit
{: #Explicit }

Syntax: **Option Explicit**

Used at the [module level](/tB/Gloss.md#module-level) to force explicit declaration of all [variables](/tB/Gloss.md#variable) in that [module](/tB/Gloss.md#module).

If used, the **Option Explicit** statement must appear in a module before any [procedures](/tB/Gloss.md#procedure).

This option makes it mandatory to require variable declarations. There is no complementary option to make the declarations optional.

When **Option Explicit** appears in a module, all variables must be explicitly declared by using the [**Dim**](/tB/Core/Dim.md), [**Private**](/tB/Core/Private.md), [**Public**](/tB/Core/Public.md), [**ReDim**](/tB/Core/ReDim.md), or [**Static**](/tB/Core/Static.md) statements. Attempting to use an undeclared variable name raises an error at [compile time](/tB/Gloss.md#compile-time).

Without the **Option Explicit** statement, and when the [**Option Explicit On**](/tB/IDE/Project-Settings.md#option-explicit-on) project setting is changed to its non-default value of *No*, all undeclared variables are of **Variant** type unless the default type is otherwise specified with a [**Def**_type_](/tB/Core/Deftype.md) statement.

> [!NOTE]
> The **Option Explicit On** project setting is *Yes* by default in new projects.

**Option Explicit** prevents incorrect typing of an existing variable's name, and removes confusion where the [scope](/tB/Gloss.md#scope) of a variable is not clear.

### See Also
{: .no_toc }

- [**Const**](/tB/Core/Const.md), [**Dim**](/tB/Core/Dim.md), and [**Static**](/tB/Core/Static.md) statements

### Example of use at module level
{: .no_toc }

```tb check_build expect-error=TB5079
Module MyModule
    Option Explicit ' Force explicit variable declaration.
    Dim MyVar ' Declare variable.
    Sub Example()
        MyInt = 10 ' Undeclared variable generates error.
        MyVar = 10 ' Declared variable does not generate error.
    End Sub
End Module
```

## Option Compare
{: #Compare }

Syntax: **Option Compare** { **Binary** \| **Text** \| **Database** }

If used, the **Option Compare** statement must appear in a [module](/tB/Gloss.md#module) before any [procedures](/tB/Gloss.md#procedure).

The **Option Compare** statement specifies the [string comparison](/tB/Gloss.md#string-comparison) method (**Binary**, **Text**, or **Database**) for a module. If a module doesn't include an **Option Compare** statement, the default text comparison method is **Binary**.

* **Option Compare Binary** results in string comparisons based on a [sort order](/tB/Gloss.md#sort-order) derived from the internal binary representations of the characters. In Microsoft Windows, sort order is determined by the code page. A typical binary sort order is shown in the following example:

  ```text
  A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø 
  ```

* **Option Compare Text** results in string comparisons based on a case-insensitive text sort order determined by the system's [locale](/tB/Gloss.md#locale). When the same characters are sorted by using **Option Compare Text**, the following text sort order is produced:

  ```text
  (A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø) 
  ```
* **Option Compare Database** has no effect in twinBASIC. When used within Microsoft Access, it results in string comparisons based on the sort order determined by the locale ID of the database where the string comparisons occur.

### See Also
{: .no_toc }

- [**InStr\$**](/tB/Modules/Strings/InStr.md), [**InStr**](/tB/Modules/Strings/InStr.md), [**InStrB**](/tB/Modules/Strings/InStr.md), and [**InStrRev**](/tB/Modules/Strings/InStrRev.md) functions.

### Example
{: .no_toc }

This example uses the **Option Compare** statement to set the default string comparison method. The **Option Compare** statement is used at the module level only.

```tb check_build
Module ModBin
	' Set the string comparison method to Binary. 
	Option Compare Binary ' That is, "AAA" is less than "aaa". 
End Module

Module ModText
	' Set the string comparison method to Text. 
	Option Compare Text ' That is, "AAA" is equal to "aaa". 
End Module
```

## Option Private
{: #Private }

Syntax: **Option Private Module**

When used in applications that reference multiple [packages](/tB/Gloss.md#package), **Option Private Module** prevents a [module's](/tB/Gloss.md#module) or [class's](/tB/Gloss.md#class) contents from being referenced outside its package.

If used, the **Option Private** statement must appear at [module level](/tB/Gloss.md#module-level) or [class level](/tB/Gloss.md#class-level), before any [procedures](/tB/Gloss.md#procedure).

When a module contains **Option Private Module**, the public parts, for example, [variables](/tB/Gloss.md#variable), [objects](/tB/Gloss.md#object), and [user-defined types](/tB/Gloss.md#user-defined-type) declared at the module level, are still available within the [project](/tB/Gloss.md#project) containing the module, but they are not available to other applications or projects.

> [!NOTE]
> **Option Private** is a more verbose way of making modules or classes private to the package. An equivalent effect in a less verbose fashion is obtained with [**Private**](/tB/Core/Private.md) statement as follows:
>
> ```tb check_build
> Private Module MyModule
>     ' ...
> End Module 
> 
> Private Class MyClass
>     ' ...
> End Class
> ```

### Example
{: .no_toc }

This example demonstrates the **Option Private** statement, which is used at module level to indicate that the entire module is private. With **Option Private Module**, module-level parts not declared **Private** are available to other modules in the project, but not to other projects or applications.

```tb check_build
Module MyModule
    Option Private Module ' Indicates that the module is private.
End Module    
```
