Navigation bar
  Start Previous page
 76 of 156 
Next page End 71 72 73 74 75 76 77 78 79 80 81  

70
An alternate form of conditional directive allows you to specify an expression involving conditional
identifiers and integer or string literals, the Boolean value of which determines whether the code within
the conditional block is processed normally or not.
#if <expression>
<other-text>
#elseif <expression>
<other-text>
#else
<other-text>
#endif
The <expression> element may be any legal ZBasic expression involving constants, conditional
identifiers and ZBasic operators.  The usual type-compatibility rules apply, e.g., you cannot add an
integral value and a string value.
The #elseif clause in the conditional construction may appear zero or more times.  The #else clause
may appear at most once.  The <other-text> element represents arbitrary text and may contain other
conditional constructs.  There is no practical limit on the nesting of conditionals.
Examples
#if Version >= 23
    #ifdef EXPERIMENTAL
    ' prepare the external circuitry and activate it
    Call TestSetup(i)
    Call PutPin(12, j)
    #endif
#endif
#if (Version >= 23) And (EXPERIMENTAL <> 0)
    ' prepare the external circuitry and activate it
    Call TestSetup(i)
    Call PutPin(12, j)
#endif
The two examples above have the same effect.
Conditional identifiers may be used in definitions, statements, and expressions as if they were constants
defined using the Const definition (but the converse is not true).
#define Version "V1.0"
#define arraySize 26
Dim myArray(1 To arraySize) as Byte
debug.print Version
One implication of this is that adding a definition of a conditional identifier may result in a compiler
message related to a Const definition warning about duplicate definitions.  Conditional identifiers defined
using a compiler option are visible in all modules while those defined in a particular module are only
visible in that module.  Also note that conditional identifiers are essentially module-level constants.  This
is true even if they are defined in a procedure.  A consequence of this is that in spite of whether a
conditional identifier is defined inside a procedure or not, its value is visible to all subsequent conditional
expressions in the module.
Previous page Top Next page