1.4 #IF ... #EIF - Decisions in Macros

<< Click to Display Table of Contents >>

Navigation:  2. Components > 1. PreProcessor & EXE-Compiler >

1.4 #IF ... #EIF - Decisions in Macros

#IF ... #EIF - Decisions in Macros            

Previous Top Next


Preprocessor-Directives

 

#IF / #EIF

Two way decisions in Macros

 

 

Intention

 

All Commands starting with a "#" are Preprocessing Commands. The #IF commands can only be used inside Macros. See chapter MACRO-Definition.

 

These commands are used by the built-in preprocessor to change the code before execution. They will not be available in the code at runtime. These commands have no access to Variables and Runtime Resources. These commands will influence the code before it is actually starting.

 

These #IF Commands can be nested to unlimited Depth.

 

#IF is a special "expansion-time evaluation"

 

The following two #IF ... #EIF are supported:

 

#IF PARAMS[condition][number or formula in ()]

[code]

#ELS

[code]

#EIF

 

and

 

#IF RECURS[condition][number or formula in ()]

[code]

#ELS

[code]

#EIF

 

To influence Macro-Expansion at resolving-time. Use >,<,= or ! as condition. Please note that number must be any real number. Variables can not be taken at this place (except §§§00 and §§§99. While §§§98 can be used at this place, its expanded to a decimal number at this place. §§§97 can not be used at this place).

 

Inside Macro-Definitions you can use these special variables:

 

- §§§95 - unique variable-counter variable, Format "000"

- §§§96 - unique variable-counter variable, Format "00"

- §§§97 - unique variable-counter variable, kein Format

- §§§98 - unique-Label counter-variable, kein Format

- §§§99 - actual recursion-depth at expansion time

- §§§00 - number of Parameters given to the Macro at call-time

 

Macro-Parameter Substitution:

 

§§§01  through §§§90  will be substituted with the parameters, which are given to the Macro at call-time. Macro-Parameter must be separated with | (Pipe-Symbol/ASC 124).

 

 

Syntax:

 

#IF PARAMS[operator][value]

...

#EIF

 

 

Parameter Explanation:

 

Operator - can be any of: >,<,=, !

value - Number, will be compared to the number of parameters actually given to this Macro call. Based on result of the compare operation, the block is been added or removed from processing code.

 

 

 

#IF RECURS[operator][value]

...

#EIF

 

 

Parameter Explanation:

 

Operator - can be any of: >,<,=, !

value - Number, will be compared to the actual recursion depth inside macro expansion. Based on result of the compare operation, the block is been removed from processing code or not. Can be used to break recursive Macro calls at a specified depth.

 

 

 

Example:

 

'-----------------------------------------------------------

' Macro-Example 1

' Please start "TestApp_01.exe" from the TestApp Folder

'-----------------------------------------------------------

 

: %Press 1

PRT.Forall

#IF PARAMS=1

SCW.ct|button|§§§01

MLC.

PRT.Nur 1 Parameter

#EIF

#IF PARAMS=2

SCW.ct|button|§§§01

MLC.

PRT.Zweiter: §§§02

#EIF

END%

 

'Move pointer to NonClient-Area.

STW.ct|PBWindowClass:0|TestApp

 

FOR.§§LOP|1|4

 %Press Button 1

 %Press Button 2

 %Press Button 3|we did it!

NEX.

 

DMP.

MBX.Thats all.

END.

ENR.

'----------------------------------------

 

'----------------------------------------

' Macro-Example 2

'----------------------------------------

' Minimum Number of parameters is set to zero

: %MyMacroA 0

PRT.Number of Parameters:§§§00-Parameter=§§§01

END%

 

' Minimum Number of parameters is set to 1

: %MyMacroB 1

%MyMacroA Mytext

PRT.Number of Parameters:§§§00

END%

 

 

%MyMacroA Mytext

 

%MyMacroB Mytext

 

 

DMP.

END.

 

 

'----------------------------------------

' Macro-Example 3

'----------------------------------------

PRT.Running

: %Parameter 1

' Example for Macro-unique variable using §§§97

VAR.$$V§§§97=unique Variable

JMP.Label§§§98

PRT.Forall

#IF PARAMS=1

 PRT.Only 1 Parameter: §§§01

#ELS

 PRT.Not only 1 Parameter: §§§01,§§§02

#EIF

#IF PARAMS>2

 PRT.More then 1 Parameter: §§§01,§§§02

#ELS

 PRT.3 or more then 3 Parameter

#EIF

' Example for a Macro-unique Label, using §§§98

:Label§§§98

PRT.$$V§§§97

PRT.Macro-Recursion-Depth=§§§99

PRT.Macro- got §§§00 Parameters.

#IF RECURS<5

 %Parameter §§§01

#EIF

END%

 

 

%Parameter 1

%Parameter 1|2

%Parameter 1|2|3

 

DMP.

MBX.1

END.

 

 

Remarks:

 

-

 

 

Limitations:

 

#IF RECURSE  uses a Simple Algo. Internally it will check if the last resolved MACRO-NAME is equal to the currently resolved MACRO-NAME and if the MACRO-Definition contains the same Name in Code.
In this case it will increase the RECURSE-Counter.
This may fail under complex Conditions where multiple Macros are being called from within the same Macro. It will also fail, if a Macro A calls a Macro B that will call Macro A again.

We recommend to carefully examine, if #IF RECURSE does work in your case.

If not use an non-recursive algo.

 

Calling Macros from within Macros is supported. "Direct nesting" of #IF PARAMS is supported.

Below are two examples. Both will work as expected.

 

' Manually formatted code

' Nesting of #IF ...

: %Loc_Edit

#IF PARAMS=0

  GSB.Loc_Edit

#ELS

  #IF PARAMS=1

    GSB.Loc_Edit|§§§01

  #ELS

    #IF PARAMS>1

      MBX.More Params are not supported (§§§00)(§§§01)!

      END.

    #EIF

  #EIF

#EIF

END%

 

 

 ' Example 2, nested #IF

: %Loc_Edit

#IF PARAMS=0

  GSB.Loc_Edit

#ELS

  ' Nesting is currently NOT supported

  #IF PARAMS=1

    GSB.Loc_Edit|§§§01

  #ELS

    MBX.More Params are not supported!

    END.

  #EIF

  '--- The #ELS case will be included

#EIF

END%

 

 

Below is the same code in a serial way that.

 

: %Loc_Edit

#IF PARAMS=0

GSB.Loc_Edit

#EIF

#IF PARAMS=1

GSB.Loc_Edit|§§§01

#EIF

#IF PARAMS>1

MBX.More Params are not supported!

END.

#EIF

END%

 

 

 

See also:

 

    : - MACRO-Definitions

    #ONCE / # OEND

    2.1.A #LIB: - User-Library Path