Start Back Next End
  
ZBasic Language Reference
61
ZBasic Microcontrollers
In the second assignment, the enumeration name is used as a qualifier on the enumeration member
name.  This is always allowed but it is only required when ambiguity exists.  See the discussion below for
additional information on resolving ambiguity.
The numeric value of a member may be obtained by using System Library type conversion functions. 
Continuing the example from above:
Dim i as Integer, j as Integer
...
i = CInt(animal)
i = CInt(Mammal.Dog)
It is also possible to convert an integral value to an enumeration member.  There are two ways to
accomplish this.  The first, and recommended, way is to use the System Library function CType().  This
function takes two parameters, the first being the integral value to convert and the second being the name
of the enumeration.
animal = CType(3, Mammal)
The conversion will be performed even if the value specified does not actually correspond to any member
of the enumeration so this type of conversion must be used carefully.
Wherever it is used, an enumeration name may be qualified with the module name containing the
enumeration.  Assume that the enumeration defined above exists in a module named Test.
animal = Test.Mammal.Dog
animal = CType(3, Test.Mammal)
Qualification using the module name is only necessary in unusual cases but it is well to remember that it
is allowed for the situations where you need it.
For an enumeration defined within a subroutine or function, the enumeration may be qualified with the
subroutine/function name, optionally preceded by a module name qualification.  For example, if the
enumeration Mammal is defined in the subroutine Main() contained in the module Test, the following
constructions are permitted within the Main() subroutine.
animal = Main.Mammal.Dog
animal = Test.Main.Mammal.Dog
When resolving a reference to a member name, the following order is used.  If the member reference
occurs within a subroutine or function, the name is first checked against the set of members of all
enumerations defined within that subroutine or function.  If only one enumeration has a matching member
name, no ambiguity exists.  If no match was found, the name is next checked against the set of members
of all enumerations defined to be private to the module.  If only one enumeration has a matching member
name, no ambiguity exists.  If no private enumerations have a matching member, the public enumerations
of all modules are checked next.  Again, if only one enumeration has a matching member name, no
ambiguity exists.  This search order may be overridden by qualifying the member name with the name of
the enumeration to which it belongs.  The reference may be further qualified by adding the module name. 
This allows access to a public enumeration that is being hidden by an enumeration that is private to the
module.
The only operations that can be performed on enumeration variables are comparison using relational
operators, assignment and type conversion.
BasicX Compatibility Note
In BasicX compatibility mode, enumerations may only be defined at the module level and
qualification of an enumeration is not supported.  Also, the values of enumeration members
are only 8-bits wide in BasicX while they are 16-bit values in ZBasic.
Previous page Top Next page