Difference between revisions of "OPTION BASE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>SMcNeill
(style guidelines)
Line 1: Line 1:
The {{KW|OPTION BASE}} statement is used to set the default lower bound of arrays.
+
The [[OPTION BASE]] statement is used to set the default lower bound of arrays.
  
  
 
{{PageSyntax}}
 
{{PageSyntax}}
:{{KW|OPTION BASE}} {0|1}
+
: [[OPTION BASE]] {0|1}
  
  
 
{{PageDescription}}
 
{{PageDescription}}
 
* This statement affects array declarations where the lower bound of a dimension is not specified.
 
* This statement affects array declarations where the lower bound of a dimension is not specified.
* When used, {{KW|OPTION BASE}} must be used before any array declarations ({{KW|DIM}}) to be affected.
+
* When used, [[OPTION BASE]] must come before any array declarations ([[DIM]]) to be affected.
 
* By default, the lower bound for arrays is zero, and may be changed to one using the statement.
 
* By default, the lower bound for arrays is zero, and may be changed to one using the statement.
 
* Otherwise, arrays will be dimensioned from element 0 if you DIM just the upper bounds.
 
* Otherwise, arrays will be dimensioned from element 0 if you DIM just the upper bounds.
* You can also set other array boundaries by using {{KW|TO}} in the DIM such as: DIM array(5 TO 10)
+
* You can also set other array boundaries by using [[TO]] in the DIM declaration such as {{InlineCode}}DIM array(5 TO 10){{InlineCodeEnd}}
* Note: Neither '''OPTION''' nor '''BASE''' can be used as numerical variable names.
+
* Note: '''OPTION''' and '''BASE''' cannot be used as numerical variable names.
  
  
 +
{{PageExamples}}
 
''Example 1:'' Set the default lower bound for array declarations to one.
 
''Example 1:'' Set the default lower bound for array declarations to one.
 
{{CodeStart}}
 
{{CodeStart}}
Line 44: Line 45:
  
 
{{PageSeeAlso}}
 
{{PageSeeAlso}}
* {{KW|Arrays}}, {{KW|LBOUND}}, {{KW|UBOUND}}
+
* [[Arrays]], [[LBOUND]], [[UBOUND]]
* {{KW|DIM}}, {{KW|REDIM}}, {{KW|STATIC}}, {{KW|COMMON}}
+
* [[DIM]], [[REDIM]], [[STATIC]], [[COMMON]]
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Revision as of 15:55, 16 October 2017

The OPTION BASE statement is used to set the default lower bound of arrays.


Syntax

OPTION BASE {0|1}


Description

  • This statement affects array declarations where the lower bound of a dimension is not specified.
  • When used, OPTION BASE must come before any array declarations (DIM) to be affected.
  • By default, the lower bound for arrays is zero, and may be changed to one using the statement.
  • Otherwise, arrays will be dimensioned from element 0 if you DIM just the upper bounds.
  • You can also set other array boundaries by using TO in the DIM declaration such as DIM array(5 TO 10)
  • Note: OPTION and BASE cannot be used as numerical variable names.


Examples

Example 1: Set the default lower bound for array declarations to one.

OPTION BASE 1 ' Declare a 5-element one-dimensional array with element indexes of one through five. DIM array(5) AS INTEGER PRINT LBOUND(array)

1


Example 2: Set the default lower bound for array declarations to zero.

OPTION BASE 0 ' Declare an 18-element two-dimensional array with element indexes of zero through two ' for the first dimension, and 10 through 15 for the second dimension. DIM array(2, 10 to 15) AS INTEGER PRINT LBOUND(array, 1) PRINT LBOUND(array, 2)

0 10


See also



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page