Start Back Next End
  
ZBasic Language Reference
32
ZBasic Microcontrollers
Within a subroutine or function you can define variables and use statements to implement the logic
required for the functionality of the routine.  This section describes the types of statements available. 
ZBasic statements may be divided into two general categories: simple and compound.  An example of a
simple statement is the assignment statement where the entire statement is expressed on one line
(ignoring possible line continuations).  In contrast, a compound statement comprises two or more lines
and may contain other statements within it.  In many respects, it is convenient to think of a compound
statement as if it were a single statement even though it may have many constituent statements.
2.5.1 Assignment Statement
The assignment statement is perhaps the most basic and most often used statement in a program.  The
syntax of an assignment statement is shown below in two forms, one for assigning a value to a scalar
variable and one for assigning a value to an array element.
<var-name> = <value>
<var-name>( <index-list> ) = <value>
In both cases, the <value> element may be a simple value or a complex expression involving one or
more other variables, constants, functions, etc.  However, the type of <value> must match the type of
the variable or array element to which it is being assigned.  There is no automatic type conversion.
When assigning a value to an array element, you must specify the index or indices of the particular
element of interest.  For a single-dimensional array, you will specify a single value for the index of the
desired element.  For multi-dimensional arrays, you must specify a value for each of the indices
separated from one another by a comma.
Example
Dim i as Integer
Dim ia(1 to 5) as Integer
Dim board(1 to 12, 1 to 12) as Byte
i = 2
ia(i) = (ia(3) + 2) / 4
board(i, 6) = CByte(ia(2))
2.5.2 Call Statement
The Call statement is used to invoke a subroutine.  The syntax is:
Call <subroutine-name> ( [<parameter-list>] )
The optional <parameter-list> must contain the proper number of parameters each of the correct
type for the subroutine being invoked.  If more than one parameter is given each parameter must be
separated from the next by a comma.
When this statement is executed the supplied parameters, if any, are pushed on the stack and control is
transferred to the first statement of the subroutine.  When the subroutine finishes executing control
resumes with statement following the Call statement.
Although not recommended, for compatibility with other Basic dialects it is permissible to omit the Call
keyword.  If this is done the parentheses surrounding the parameter list must also be omitted.  Note,
particularly, the third example below that seems to violate this rule.  However, it does not because a
parenthesized expression is, in fact, an expression.
Previous page Top Next page