PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: #Error[Next]: #ifdef
\ -> Commands -> #if


A #if command (like #ifdef and #ifndef) can be used to conditionally include lines of text, this can be any other type of line or command except #elseif or #endif. As an example of its use, #if allows you to examine the machine it is running on (for example its environment variables) and generate the appropriate code.

#if commands can be nested to any level and there need not be any lines between a #if and a #endif or #elseif command.

There are two forms of this command. The second exists only to speed up the performance, it supplies a small subset of the full functionality but is very much faster.

Syntax #1 - Full Functionality (but slower)

[WhiteSpace]#if  ValidRexxCondition

The "ValidRexxCondition" specifies a valid rexx conditional test which results in a TRUE or FALSE answer. The condition may be as complex as you wish and may include the special GetEnv() function (or many others) to obtain information from the environment. For complex logic an external rexx script could be called, these can return numeric or text return codes.

Syntax #2 - Partial Functionality (but fast)

It is recommended that this form be used where possible if you have many tests in your code, if you only have a few you probably don't need to bother. This form does a single compare between two simple values. The square brackets surrounding the compare are used to indicate that this form is supplied by the user.

[WhiteSpace]#if  [Value1  Operator  Value2]

The "Operator" parameter should have whitespace to either side and be one of the following:

  1. == Strict compare for equal.
  2. = Compare for equal.
  3. <> Compare for not equal.
  4. < Less than.
  5. > Greater than .
  6. <= Less than or equal.
  7. >= Greater than or equal.

The Value1 & Value2 parameters can be one of the following:

Example #1 - File Exists?

;--- One possibility ---
#if FileQueryExists('licence.txt') <> ''
    <P>The file "licence.txt" exists (in current directory).

;--- Another possibility ---
#if FindFile('licence.txt') <> ''
    <P>The file "licence.txt" found.

Example #2 - Check environment variable

;--- Don't not display following graphics on works INTRANET! ---
#if translate(GetEnv("PRJSRCDIR")) = "E:\DB\PROJECTS\HOMEPAGE"
    <CENTER><IMG SRC="graphics/fatguy.gif" BORDER=0 WIDTH=182 HEIGHT=181></CENTER>

;--- A better way to do the above ---
#if ["<?*PRJSRCDIR $$upper>" = "E:\DB\PROJECTS\HOMEPAGE"]
    blah blah

Example #3

#define StupidExampleMacro                                                             \
        <P>Hi, my name is Dennis Bareis and I have been using OS/2 and developing for  \
        #if ['<$AtWork>' = 'Y']                                                        \
           BNZ                                                                         \
        #elseif                                                                         \
           *WRONG INC*                                                                 \
        #endif                                                                          \
        on and off since the original 1.0 version.

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: #Error[Next]: #ifdef

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Saturday May 28 2022 at 2:55pm