Navigation bar
  Start Previous page
 49 of 206 
Next page End  

ZBasic Language Reference
41
ZX Microcontroller Family
continuation character.  The maximum aggregate size of a line, whether continued across multiple lines
or not, is 1000 characters.
In the example below the beginning of the If statement is continued to the following line.  This is often
useful to help make more complex expressions more readable.
Example
If (GetPin(20) = 1) And _
    (GetPin(12) = 0) Then
  Call PutPin(5, 0)
End If
While the line continuation capability allows you to create statements that span multiple lines, it is
sometimes convenient to place multiple statements on one line.  In ZBasic, as in many other Basic
dialects, you may accomplish this by using a colon to separate each pair of statements on the line.
Example
Dim i as Integer
Dim j as Integer, k as Byte
i = 0 : j = 1 : k = 2
2.9 Persistent Variables
You may define variables that are stored in the processor’s internal EEPROM, referred to in this
document as Persistent Memory.  It is called persistent because the values that you store there are
retained even if the system is powered down or reset.  This characteristic makes persistent variables
useful for storing configuration information for your application and other similar information that your
application needs to be preserved.
A persistent variable is defined at the module level using the syntax:
{Public | Private | Dim} <name> as Persistent <type>
Using the keyword Dim has the same effect as using Private.  Within a subroutine or function, a
persistent variable is defined using the syntax.
Dim <name> as Persistent <type>
In both cases, the <type> element may be any numeric type (e.g. Byte, Integral, Single, etc.), Boolean or
a user-defined type (structure or enumeration).  A persistent string must be defined using the bounded
Dim <name> as Persistent BoundedString(<size-expr>)
The <size-expr> element must be a constant integral expression that specifies the number of bytes to
reserve for the persistent string’s characters.
Examples
Dim kbdAttached as Persistent Boolean
Private signOnMsg as BoundedString(25)
It is important to note that the implementation of the PersistentString type is identical to that of the
BoundedString type and is therefore not protected from overwriting the boundaries of the data item.  To
protect against overwriting, it is advisable to explicitly limit the size of the string to be written.
Previous page Top Next page