#if
Topic group Related topics Example
Controls conditional compilation of code based on the value of an identifier assigned with #define.
Syntax
#if <condition>
<statements 1>
[#else
<statements 2>]
#endif
<condition>
A logical expression, using an identifier you’ve defined, that evaluates to true or false.
<statements 1>
Any number of statements and preprocessor directives. These lines are compiled if <condition> evaluates to true.
#else <statements 2>
Specifies the lines you want to compile if <condition> evaluates to false.
Description
Use the #if directive to conditionally compile sections of source code based on the value of an identifier. Two other directives, #ifdef and #ifndef, are also used to conditionally include or exclude code for compilation. Unlike the #if directive, however, they test only for the existence of an identifier, not for its value.
The <condition> must be a simple logical condition; that is, a single test using one basic comparison operator (=, ==, <, >, <=, >=, <>). You may nest conditional compilation directives.
If the identifier is not defined, the <condition> always evaluates to false.
Conditional compilation is useful when maintaining different versions of the same program , for debugging, and for managing the use of #include files. Using #if for conditional compilation is different than conditionally executing code with an IF statement. With IF, the code still gets compiled into the resulting byte code file, even if it is never executed. By using #if to exclude code you don’t want for a particular version of your program, the code is never compiled into byte code.
When dBASE Plus’s preprocessor processes a file, it internally defines the preprocessor identifier __version__ (two underscores on both ends) with the current version number. Earlier versions of dBASE used __dbasewin__ and __vdb__. Use these three built-in identifiers to manage code that’s intended to run on different versions of dBASE.
The numeric values returned by these identifiers are as follows:
__dbasewin__ : 5.0 for dBASE 5.0, and 5.5, 5.6 or 5.7 for the versions of Visual dBASE 5.x
__vdb__ : 7.0, 7.01, 7.5 for Visual dBASE 7.x and 2000 for dBASE versions after Visual dBASE 7.5
__version__ : 1.0, 2.0, etc. depending on the release of a dBASE version after Visual dBASE 7.5
Note
The display of the above values will be affected by the number of decimal places specified by SET DECIMALS, and the separator specified by SET POINT.