this module will cover - minitab...
TRANSCRIPT
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 1
MTB – 03 Minitab® Macros
This module will cover:
• The Command Prompt ( & a one time set up)
• Capturing Commands • Capturing Commands from Modified Graphs
• Submitting Commands
• Your First Macro
• Local vs Global Macros
• Debugging macros
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 2
Prerequisites
Before you tackle this module you
should:
– Know the basics of Minitab
– Know how to modify graphs (Change
symbols, axis ranges, etc.).
– Know where to find and how to use
NotePad or another “plain text” editor. • Microsoft Word® is not a good text editor for macros
but can be used if you save the file as Text Only (*.TXT)
and change the extension to .MAC while saving.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 3
One Time Set Up of Minitab®
This set up changes the options for Minitab on
a computer to turn on the Command Prompt.
1. Click Tools > Options…
2.Expand the Session Window options, click on Submitting Commands and then click the button for Command Language Enable.
3.Click OK to save all your option changes.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 4
One Time Set Up – cont’d
You now see the MTB> command prompt in the
Session Window.
Having the MTB > command prompt enabled has advantages: 1. You see and can easily “capture*” the commands that Minitab uses for
most operations. 2.You can execute macros or “execs” or issue commands directly from the
prompt. (This can be faster than drilling down through the Graphical User Interface in some cases and it can be useful for debugging).
3.From within a macro you can request user input – (eg. “How many months of data do you want returned?”).
The disadvantage? More clutter in the Session Window.
* The History Window also allows you to capture commands, even if the session command prompt is not turned on.
Behind Minitab’s Graphical User Interface beats the heart of a 30+ year old command line interface. For most operations what you select from the graphical user
interface defines the commands submitted to Minitab’s command processor. Once the command prompt is enabled,
the Session Window will display these commands.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 5
Capturing Commands
Here we have interactively input data
into the worksheet.
Notice that nothing has been displayed in the
session window.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 6
Capturing Commands - cont’d
Using Graph >
Time Series Plot… we plot
the data.
Notice that the commands corresponding to this graph show up in the session window
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 7
Capturing Commands - cont’d
We interactively customize the graph. (The Title, the X-axis
title, the plot symbol and the connect line.)
Notice that no new commands show up in the session window. How do we capture
the commands needed to create this
modified graph??
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 8
Capturing Commands - cont’d
Making sure the graph has “focus” (by clicking on it), we use the menu
option, Editor > Copy Command Language .
This puts the Session Commands needed to create the graph in
the windows clipboard.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 9
Capturing Commands - cont’d
If we open Notepad (from Windows: Start > Accessories > Notepad), and paste in the contents of the clipboard (Edit >
Paste), we can see these commands.
Some of the sub-commands have “sub-sub-commands” if you will – eg. Type 16; follows the Symbol; sub-command and indicates
that symbol type 16 is to be used (a diamond).
Note that the overall command TSPlot has sub-commands. The sub-commands end with a semi-colon and the overall command ends with a period.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 10
Executing Commands
• You can execute session commands directly at the MTB> prompt. This the way you would have interacted with Minitab in the 1980’s!
• Here is use of the
INFO command:
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 11
Executing Commands
• You can also execute session commands via the Command Line Editor window which can be brought up with Ctrl/L
• Here we have pasted the commands captured from the modified graph. When you Submit the commands the graph will be generated.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 12
Your First Macro
Steps to create a macro: 1. Capture some session commands and paste them into
Notepad. (You must use an editor that saves files as plain text. Notepad does this.)
2. Optional (but recommended): Above the session commands put in header lines describing the macro. In Minitab® comments follow the character #.
3. Enter on a separate line above the session commands GMacro.
4. On the line following GMacro enter a name for the macro (no spaces). It is highly recommended to have this name match the name of the file you will create. (eg. If your file will be TestPlot.mac then name your macro TestPlot).
5. As the last line of the file enter EndMacro.
6. Save the file with the file name of e.g. TestPlot.mac. If you are using Notepad you need to save it as file type All Files (*.*) otherwise it will create the file TestPlot.mac.txt
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 13
Your First Macro - cont’d
Optional comments
First command for any global macro
The name of the macro
The commands to be executed
The last command for any global macro
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 14
Executing your first macro
There are two options to execute your macro: 1. At the MTB> prompt enter % immediately followed
by the name of the macro. If you have saved the file in the default folder for Minitab macros (as shown in Options > General), then you would only need to enter
%TestPlot
If it is in some other folder you would need to enter the full filename including path eg.
%"C:\MASIBLEY CONSULTING\MINITAB\MACROS\TESTPLOT.MAC"
Note: if the path or filename includes a space you will need to include the " before and after the full filename as shown.
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 15
Executing your first macro - cont’d
2. From a My Computer / Explorer window,
click on the file listing, drag and then drop
on the Minitab® Window. You should see a
window pop up. Press <Execute>.
Note: if the path or filename includes a space you will need to include a " after the % and another at the end of the full filename before you press <Execute>. Dumb behaviour on Minitab’s part!
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 16
Local vs Global Macros
Minitab provides the capability to run both “Local” and “Global” macros. Each types has its pros and cons.
– Local Macros: • These start with the command Macro.
• These are more difficult to develop and debug because they work on hidden worksheets.
• They have the advantage that you can pass parameters to them. For example, you might create a local macro to create a simple time series plot similar to our previous example. You could then have it defined so you would tell it which column you wanted to use for the graph. e.g. %TestPlot C1
M. A. Sibley Consulting – All Rights Reserved MTB 03 – Minitab Macros 17
Local vs Global Macros - cont’d
– Global Macros:
• These start with the command GMacro.
• These are easier to develop as you can work
with normal (visible) worksheets. This allows
you to execute Minitab menu driven
commands, capture them, and then add them
to the macro you are developing. In this way
you can create complex macros in sections.
Unfortunately you cannot mix Local and
Global macros.