Option Base Command

Purpose

Sets the starting offset for row/column indexing of arrays.

Sets the starting offset for random I/O files to 0 or 1.

Syntax

Option Base [an] [, rb]

an, rb:iexp

Description

The Option Base an command sets the starting offset for row/column indexing of arrays. In case of Option Base 0 the indexing starts with element 0, and in case of Option Base 1 with element 1. Option Base 0 is the default.

Option Base ,rb will set the default base for random I/O files to 0 or 1.

A note of caution: if an array is dimensioned under Option Base 0 and then ReDim'ed under Option Base 1, the array retains its original starting element of 0; the same happens the other way around.

Example

Option Base 1

Print "Option Base is"; CheckOptionBase

Option Base 0

Print "Option Base is"; CheckOptionBase

 

Function  CheckOptionBase

Local a%(2), rv% = LBound(a%())

Return rv%

EndFunction

Remarks

Option Base also sets the starting index of the Mat commands.

Known Issues

There are issue when Option Base 1 is set with a number of different commands, including ReDim and Array()=. See the relevant pages for more information.

In addition, you may find problems when using Option Base 1 when passing arrays using ByRef to another procedure and, on occasions, if the array was not created using Dim (i.e. the array was dimensioned using just Local or Global): in both these instances, an element '0' (zero) may be added. However, this error does not happen all the time and is one of the few 'random' errors that occur in GB32 from time to time. If these problem arise, you can generally get around them by either adding Dim to the original declaration or creating a local array within the procedure to which the array is to be passed and copying the global array into it.

See Also

Open

{Created by Sjouke Hamstra; Last updated: 17/12/2015 by James Gaite}