User Tools

Site Tools


Determining how a macro was run

by Jon Ripley, October 2007

When writing a macro it is often useful to be able to determine whether it is being run as the main program or if it has been CALLed. Making this distinction allows more flexibility when writing macros.

To determine whether the currently executing code is running as the main program or as a called module you can use either of the following methods.

Method One

        Called% = NOT(!384>=PAGE AND !384<=TOP)

Method Two

        ON ERROR P%=!408:ON ERROR OFF
        IF P%=0 ERROR
        Called%=NOT(P%>=PAGE AND P% <=TOP)

Both methods set Called% to TRUE if the program was run using “CALL “filename”” and FALSE if the program is running as the main program.

Note: The code for both methods is unsuitable for refactoring into a subroutine and must be called in-line to guarantee correct results; the code will fail in the case where a subroutine with the same name is present in the main program because the main program has precedence.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
determining_20how_20a_20macro_20was_20run.txt · Last modified: 2018/04/15 19:43 by tbest3112