
Abstract: Passing
parameters to macros
Products:
Statit
e-QC, Statit
e-Server, Statit
Custom QC
Example: You have to generate an X-bar and
R chart for some data. Let's use the workspace
shipped with Statit, qc.wrk, for this example.
In this workspace, you find three variables
that you need to do an X-bar and R chart for:
Width, Pressure, and Temperature.
So you use the Statit feature, File > Macros
> Record to create a macro to do this. The
macro contains the lines:
gxchart
Width by 5 /top
grchart Width by 5 /bottom
But this macro is only good for Width. You
also want to use this for Pressure and Temperature.
So you set this up to take as the first parameter
the name of the variable to produce the charts
for. The macro now looks like this:
gxchart
{%Measure%} by 5 /top
grchart {%Measure%} by 5 /bottom
The macro is called using name-value pairs
for the parameters:
exec
macroname (Measure=Width)
An older method of passing parameters to a
macro used what was known as positional parameters:
gxchart
@1 by 5 /top
grchart @1 by 5 /bottom
The "@1" is substituted with the
first parameter prior to execution of the command.
In the Execute dialog from Statit, you enter
the variable name in the Parameters box. If
you were typing in a command, it would look
like this:
exec
macroname (Width)
The macroname is the file name you created
this macro in, and Width is the name of the
variable. Replace Width with the variable you
want the charts created for.
Now this is pretty good, but the subgroup size
is fixed at 5. Most of the time you will have
a sub-grouping variable. This workspace has
the variable Date which should be used as the
sub-grouping variable. This can be passed as
a second parameter to the macro, rather than
hard-coding it into the commands. Update your
macro to look like this:
For Name-Value pair Method:
gxchart
{%Measure%} by {%SubGroup%} /top /nodraw
grchart {%Measure%} by {%SubGroup%} /bottom
exec macroname (Measure=Width,SubGroup=Date)
For Positional Parameter Method:
gxchart
@1 by @2 /top /nodraw
grchart @1 by @2 /bottom
The "@2" is substituted with the
second parameter prior to execution of the command.
In the Execute dialog from Statit, you enter
the variable names in the Parameters box, separated
with a comma. If you were typing in a command,
it would look like this:
exec
macroname (Width,Date)
Note that I also added the option "/nodraw"
to the X-bar chart. This prevents the display
of the graph until the R chart is ready. Thus,
you do not see the flash of one chart and then
the double chart.
This is just the start of what you can do with
parameters and Statit macros. Combine this with
macros calling macros, and the @v[ ] syntax
supported in Statit 5.2.8 and later, there are
very powerful things you can do.
If you would like additional information, please
call our Support staff at (541) 752-4100 or
send email to
.
|