Condividi tramite


#IFDEF | #IFNDEF ... #ENDIF Preprocessor Directive

Conditionally includes a set of commands at compile time if a compile-time constant is defined.

#IFDEF | #IFNDEF ConstantName 
   Commands
[#ELSE 
   Commands]
#ENDIF

Parameters

  • #IFDEF
    Specifies that a set of commands is included at compile time when the ConstantName is defined.

    The following items describe how a set of commands is included at compile time when you include #IFDEF:

    • If ConstantName is defined, the set of commands following #IFDEF and preceding #ELSE or #ENDIF (whichever occurs first) is included at compile time.
    • If ConstantName is not defined and #ELSE is included, the set of commands following #ELSE and preceding #ENDIF is included at compile time.
    • If ConstantName is not defined and #ELSE is not included, no commands within the #IFDEF ... #ENDIF structure are included at compile time.
  • #IFNDEF
    Specifies that a set of commands is included at compile time when the ConstantName is not defined.

    The following items describe how a set of commands is included at compile time when you include #IFNDEF:

    • If ConstantName is not defined, the set of commands following #IFNDEF and preceding #ELSE or #ENDIF (whichever occurs first) is included at compile time.
    • If ConstantName is defined and #ELSE is included, the set of commands following #ELSE and preceding #ENDIF is included at compile time.
    • If ConstantName is defined and #ELSE is not included, no commands within the #IFNDEF ... #ENDIF structure are included at compile time.
  • ConstantName
    Specifies the compile-time constant whose existence determines whether a set of commands is included at compile time. Compile-time constants are defined with #DEFINE.

  • Commands
    Specifies the set of commands that is included at compile time.

Remarks

You can nest an #IFDEF | #IFNDEF ... #ENDIF structure within another #IFDEF | #IFNDEF ... #ENDIF structure.

Comments can be placed on the same line after #IFDEF, #IFNDEF, #ELSE, and #ENDIF. These comments are ignored during compilation and program execution.

Example

The following example creates a compile-time constant named MYDEFINE. #IFDEF ... #ENDIF displays a message if the compile-time constant has been defined.

#DEFINE MYDEFINE 1

#IFDEF MYDEFINE   
   WAIT WINDOW "MYDEFINE exists"
#ELSE
   WAIT WINDOW "MYDEFINE does not exist"
#ENDIF

See Also

COMPILE Command | #DEFINE ... #UNDEF Preprocessor Directive | #IF ... #ENDIF Preprocessor Directive | #INCLUDE Preprocessor Directive