Page 32 of 229 Start Back Next End ZBasic Language Reference 22 ZBasic Microcontrollers Dim has exactly the same effect as Private, i.e., the variable will only be directly accessible to code within the module. Examples Dim ival as Integer, pulseCount as Byte Private busy as Boolean Dim msg as String The first example above shows two different variables being defined on the same line. The initial value of a variable depends on its type and how it is defined. See Section 2.12 for information on variable initialization. Defining Arrays of Variables Variables which hold a single value like those discussed above are called scalar variables. ZBasic also supports arrays of variables. An array of a fundamental type may be defined using the syntax: {Public | Private | Dim} <name>(<dim-spec-list>) As <type> The <dim-spec-list> is a list of up to 8 dimension specifications each separated from the next by a comma. A dimension specification consists of a constant expression giving the upper bound of elements along that dimension or two constant expressions separated by the keyword To specifying the lower bound and upper bound, respectively, of the elements along that dimension. When only the upper bound is given, the lower bound defaults to either zero or one depending on whether or not an Option Base directive is in effect or not. If no Option Base directive has been specified, the lower bound is zero. Note that in order to be passed as a parameter to a subroutine or function an array must have a lower bound of 1. For this reason it is probably more common to define arrays with a lower bound of 1. Many people find it easier to think about arrays this way as well. The default lower bound of zero is kept for compatibility reasons. Examples Option Base 0 Dim ival(5) as Integer This defines an array of Integer values with 6 elements. The lower bound is zero and the upper bound is 5. Option Base 1 ... Dim ival(5) as Integer This defines an array of Integer values with 5 elements. The lower bound is 1 and the upper bound is 5. The lower bound may be explicitly specified as well. The second example below illustrates the use of a negative value as one of the bounds. Note that the upper bound must be greater than or equal to the lower bound. Public pulseCount(1 to 6) as Byte Private itemData(-3 to 45, 1 to 4) as Boolean You may also define an array of strings but only when Option AllocStr is in effect as it is by default.