This recipe will create a complicated macro using control statements and subcommands on the main macro command.
The following macro will be able to accept any number of columns on the main command line and generate a layout for each column. Specifications can be optional; they can be entered as a column or a single value. We will use a column for the specifications to allow different specifications for each column of data, or a constant to use the same specification for each column. The macro will be able to choose between the layout with or without specifications and perform an error check to see if the right number of specifications have been entered. This will cover several nested IF
statements and DO
loops.
Finally, we will copy the Llayout macro from the previous recipe into Notepad twice and edit this macro to create two submacros. One will be used to generate a layout for specifications and we will edit the other to create a layout when no specifications are used.
We will need the Llayout.mac
file from the Creating a Local macro recipe or the catch-up file, Llayout.mac
.
The following steps will convert the Llayout macro to use any number of columns as an input. We will also add a subcommand to use specifications as either a constant or a column:
LSub.mac
in the macro folder.IF
statements as a way to check if the specification subcommand has been used and to identify if it is a constant.ENDMACRO
.NOSPEC
.SPEC
and GROUP
from the NOSPEC
macro.TSPLOT
commands by removing the GROUP
and Reference
subcommands. Ensure that the TSPLOT
command appears as follows:30
.c1-c5
.10
.Specifications
.11 11.5 * 12.5 13
in the Specifications
column.%LSub c1-c5;
command and press Enter to go to the next line.Specs c6.
and click on Submit Commands.Subcommands that are entered on the macro name line allow optional commands to be entered. When running the macro, we can decide whether we want to use specifications or not.
The use of the Mfree
command here allows a single specification to be entered as a constant; if separate specifications are desired, we can enter a column from the worksheet because Mfree
will set its variable type based on the variable that is being passed to the macro. The Mtype
command is then used to ask what variable type we have in SPC
.
The first IF
statement checks if the SPECS
subcommand was used. If it was, then we check if the specifications were entered as a constant or column. If they are entered as a column, then we check if the number of specifications match the number of columns with the count of SPC
compared to N
.
To avoid rewriting the graph code several times, we store this in two separate macros: Llayout and Nospecs. If we want to remove excess code, we could further tidy this by placing the Pplot
and the Histogram
command in a third macro. As these commands haven't used specifications, using a third submacro could reduce the number of lines used.
The Miss()
function is used to identify the missing values in the worksheet. It has been used here to identify when missing values have been entered for specifications. This allows us to not include a specification for some columns.
3.144.252.204