Difference between revisions of "OPTION BASE"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
imported>Stylin
(updated to new blueprint, added descriptions and examples)
Line 1: Line 1:
'''OPTION BASE 1''' is used to set the lowest array element to 1.
+
The {{KW|OPTION BASE}} statement is used to set the default lower bound of arrays.
  
  
 +
{{PageSyntax}}
 +
:<code>{{KW|OPTION BASE}} 0|1</code>
  
 +
 +
{{PageDescription}}
 +
* This statement affects array declarations where the lower bound of a dimension is not specified. See {{KW|DIM}}, {{KW|REDIM}}, {{KW|STATIC}}, {{KW|COMMON}}.
 +
* By default, the lower bound for arrays is zero, and may be changed to one.
 +
* {{KW|OPTION BASE}} must be used before any array declarations, if at all.
 
* 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.
 
* Statement should be set before any arrays are dimensioned ([[DIM]]).
 
* Statement should be set before any arrays are dimensioned ([[DIM]]).
  
 +
 +
{{PageExamples}}
 +
{{CodeStart}}' Set the default lower bound for array declarations to one.
 +
{{Cl|OPTION BASE}} 1
 +
 +
' Declare a 5-element one-dimensional array with element indexes of one through five.
 +
{{Cl|DIM}} array(5) {{Cl|AS}} {{Cl|INTEGER}}
 +
 +
{{Cl|PRINT}} {{Cl|LBOUND}}(array)
 +
{{CodeEnd}}
 +
{{OutputStart}} 1{{OutputEnd}}
  
  
''Alternative:'' DIM arrays using upper and lower bounds as shown:
+
{{CodeStart}}' Set the default lower bound for array declarations to zero. This statement has no real effect,
 +
' but it may be useful to emphasize the default behavior in order to eliminate any chance of confusion.
 +
{{Cl|OPTION BASE}} 0
  
: DIM Array(1 TO 200)
+
' 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.
 +
{{Cl|DIM}} array(2, 10 to 15) {{Cl|AS}} {{Cl|INTEGER}}
  
 +
{{Cl|PRINT}} {{Cl|LBOUND}}(array, 1)
 +
{{Cl|PRINT}} {{Cl|LBOUND}}(array, 2)
 +
{{CodeEnd}}
 +
{{OutputStart}} 0
 +
10
 +
{{OutputEnd}}
  
''See also:'' [[UBOUND]], [[LBOUND]]
 
  
 +
<!-- the following is not needed ? -->
 +
''Alternative:'' DIM arrays using upper and lower bounds as shown:
 +
: DIM Array(1 TO 200)
  
  
==Navigation:==
+
{{PageSeeAlso}}
 +
* {{KW|LBOUND}}, {{KW|UBOUND}}
 +
* {{KW|DIM}}, {{KW|REDIM}}, {{KW|STATIC}}, {{KW|COMMON}}
  
[[Keyword_Reference_-_Alphabetical|Go to Keyword Reference - Alphabetical]]
 
  
[[Keyword Reference - By usage|Go to Keyword Reference - By usage]]
+
{{PageNavigation}}

Revision as of 03:50, 1 March 2010

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. See DIM, REDIM, STATIC, COMMON.
  • By default, the lower bound for arrays is zero, and may be changed to one.
  • OPTION BASE must be used before any array declarations, if at all.
  • Otherwise, arrays will be dimensioned from element 0 if you DIM just the upper bounds.
  • Statement should be set before any arrays are dimensioned (DIM).


Examples

' 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


' Set the default lower bound for array declarations to zero. This statement has no real effect, ' but it may be useful to emphasize the default behavior in order to eliminate any chance of confusion. 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


Alternative: DIM arrays using upper and lower bounds as shown:

DIM Array(1 TO 200)


See also



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