78 of 158
72 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. Additionally, the special operator defined() may be used in a conditional expressions. The parameter to the defined() operator should be an identifier and the result will be non-zero or zero depending on whether the identifier is defined or not. Examples #if defined(EXPERIMENTAL) Debug.Print "Experimental version" #endif #if defined(Pin.RedLED) Call PutPin(Pin.RedLED, zxOutputLow) #endif 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