Skip to content

#IFNDEF

#IfNDef

See Also: Define Command, #IfDef

Purpose

The #IfNDef command allows you to specify conditionally compiled code based on whether a symbol has not been typed (or defined). This compiler directive does the opposite of the #IfDef compiler directive.

Syntax

#IfNDef {symbol}
{code to compile if symbol is not typed}
#Else
{code to compile if symbol is typed}
#EndIf

What It Does

Any symbolic name that has a valid ICODE equivalent in the compiler's substitution table is said to be typed. Any symbolic name that has no ICODE equivalent is said to be untyped.

  • Any file element, label, or variable that you have declared is considered to be typed and would test false when given as an argument to #IfNDef.
  • On the other hand, a symbolic name such as RAZZO is meaningless to the compiler if it has not been declared as a variable, label, or some other type of data, and would cause the #IfNDef to test true.

Most often, the #IfNDef compiler directive is used to conditionally exclude code from compilation in scenarios where code is shared between Windows and Web-based applications. Web-based applications cannot use Windows-based messages and classes, such as MessageBoxes.

In this case, the programmer would check for the existence of the IS$WebApp symbol, which will test false if compiled with Web-based packages, such as AllWebAppClasses.pkg. If compiling a Windows-based application using a precompiled package such as DfAllEnt.pkg or Windows.pkg, this symbol would not be defined.

#IfNDef IS$WebApp
    send Stop_Box "The value you have typed is too large"
#EndIf

This example compiles the line of code calling the Stop_Box Windows MessageBox message only if IS$WebApp is defined.