PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: Macros With Mandatory Parameters[Next]: Macro Parameters without values (Keyword)
\ -> Macros -> Macros With Optional Parameters

Macros With Optional Parameters

The subject of macros is reasonably complex (but well worth learning) please ensure you have at least read the macro introduction before reading this section.

Also note that you can create a macro which accepts optional parameters. The "VISIBLE" parameter we have been using up to now is manditory (required), if not supplied the preprocessor will inform you of this fact and stop. To make a parameter optional you assign at least the first occurance of the parameter a default value. You can give each occurance a default value (which may be different), and the last specified default value is remembered for subsequent occurances where a default value is required but not specified. For example to change the email macro to use my email address as the default but allow the specification of alternative addresses I could do the following:

#define EmailMeLink  <A HREF="mailto:{$EMAIL='db0@bnz.com'}">{$VISIBLE}</A>

You could then say:

<P>If you have any questions or suggestions for improvements please feel free to
<$EmailMeLink VISIBLE=@email me@>, I have another
<$EmailMeLink VISIBLE=@email address@ EMAIL=$db1@bnz.com$> which
you might like to try.

Advanced Example

This example is demonstrating a bit more than just optional parameters as it is a good example on how you can to some degree simulate rexx like arrays or stem variables:

;--- Define some constants (make names likely to be unique) ---
#define    OPENIT_OPENMODE_TEXT     'T'
#define    OPENIT_OPENMODE_BINARY   'B'

;--- Allow user to specify "short" open mode! -----------------
#define    OpenIt   \
           Open({$File}, <$OPENIT_OPENMODE_{$Mode=^TEXT^}>)     ;;Call to fictional open routine

;--- Test the macro -------------------------------------------
OpenRc = <$OpenIt File="tfile">
OpenRc = <$OpenIt File="bfile" MODE="BINARY">

What the above demonstrated was a simple way of defining long names for constants with little or no chance of clashing with other variable names (possibly outside your control) but allowing the user to specify shorter more friendly aliases ("BINARY" instead of "OPENIT_OPENMODE_BINARY").


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

[Top][Contents][Search][Prev]: Macros With Mandatory Parameters[Next]: Macro Parameters without values (Keyword)


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am