.



Core Functions    
Macros

Macros - use in the report generator, super report, statistics view, global change

The macro Command is also a 4D Command, taking the same single parameter. This means that macros can be used to greatly extend the user-definable power of the Report Generator, of SuperReport and of the Global Change. The macros can be of any length, and can incorporate If and While statements.

Within the Report Generator ‘Edit a formula’ function, or in a script of an object in the body phase of a SuperReport Report, or in the Global Change dialogue box, one can simply type:

Macro ("MACRO CODE")

For example, in a simple SuperReport based on Companies, one might create a ‘mText’ variable, whose script reads:

Macro ("LOAD TEXT")

The ‘LOAD TEXT’ macro itself should be set to ‘Same Process’, and might read:

If ([COMPANIES]Company Name>"g@")

 mText:="After G"

Else

 mText:="Before G"

End if

To make the same thing happen in the Report Generator, you will need to call macro (“LOAD TEXT”) in a hidden C1 column’s Formula, and then add a C2 column with a Formula simply reading ‘vText’. Remember to turn off automatic column widths.

When used within the ‘Statistics View’ screen, the Macro Result command needs to be used instead of the macro command. Macro Result can, of course, be used in the Report Generator, Super Report and Global Change editors as well.

Macro simply calls and runs another macro, while Macro Result calls and runs the macro and accepts a numeric result back from the called macro. The existence of this result is essential if a macro is to be usefully called from the ‘Statistics View’ formula window, which itself is obtained by selecting ‘Formula’ from the lower of the two pop-up menus above columns three and four. The result is of real number format. The macro being called should load a numeric value into a variable called ‘vmResult’ (it must be exactly this name). If it does not, the result will always be zero. The format is as follows:

Macro Result ("MacroCode")

from within 4D Rep Gen or Statistics View

SRVar:=Macro Result ("MacroCode")

from within SuperReport.  The use of these methods is inevitably going to make the processing of the reports notably slower. It has to query for the macro each time, and all macros are effectively run uncompiled. Remember that macros are a fifth generation language.



 

Published date: Fri, 09 Mar 2007 13:54:00 GMT

© 2006 - 2007 Daybook Limited, All trademarks accepted. All Rights Reserved!
Site Index