ZBasic Language Reference
91
ZBasic Microcontrollers
Sub Main()
' this structure is not automatically initialized
Dim bar as foo
' this call zeroes out the entire structure
Call MemSet(bar.DataAddress, SizeOf(bar), 0)
' other code follows
End Sub
Another method of creating a user-defined type, compatible with VB6, is also supported. The syntax for a
Type definition is:
[Public | Private] Type <name>
<member-definition>
...
End Type
In this case, the <member-definition> is the same as for defining a member of a Structure except
that the visibility attribute (Public, Private, or Dim) is not allowed. The visibility of each member will
be the same as the visibility of the Type itself.
BasicX Compatibility Note
Structure and Type definitions are not allowed in BasicX compatibility mode.
3.25.1 Structures in Persistent Memory and Program Memory
Structures in Persistent Memory and Program Memory may be defined using the syntax:
{Public | Private | Dim} <name> As Persistent <type>
or
{Public | Private | Dim} <name> As ProgMem <type>
where <type> is the name of a previously defined structure. The allowable members of a Persistent
Memory or Program Memory structure are the intrinsic types Byte, Integer, UnsignedInteger,
Long, UnsignedLong, Single, bounded strings, arrays of those types and other structures containing
only those types. Arrays of structures in Persistent Memory or Program Memory may be defined by
specifying the dimensions in the usual way.
It is permissible to directly assign between any combination RAM-based, Persistent Memory and Program
Memory variables defined using the same structure. Similarly, direct comparison between like structures
(equality and inequality only) is supported.
3.26 Unions
It is occasionally useful to define a data type that is a collection of data elements superimposed on one
another, i.e. where all members occupy the same space. This yields an effect similar to defining a
variable to be an alias for another. In ZBasic, as in many other programming languages, such a
collection of data items is referred to as a union. A union is a user-defined data type similar in some
respects to a structure. As with an structure, you define a union by specifying the consituent elements.
The syntax for defining a union at the module level is:
|