Example - Recording a Simple Macro

This example illustrates how to record a macro from a simple analysis. Start STATISTICA, open the example data file Exp.sta, and select Basic Statistics/Tables from the Statistics menu.

From the Basic Statistics and Tables Startup Panel, select Descriptive statistics and click the OK button. In the Descriptive Statistics dialog box, click the Variables button and select all variables for the analysis. Then, on the Descriptive Statistics - Quick tab click the Summary: Statistics button to display the descriptive statistics summary spreadsheet. Next select the Normality tab, and click the Histograms button; histograms for all variables will be computed.

The STATISTICA Visual Basic code that will reproduce this analysis, which has been "accumulated" by the program, can be displayed in the STATISTICA Visual Basic Editor in several ways. If the current analysis dialog box is minimized:

Ribbon bar. Select the Home tab. In the Tools group, click Macro and from the Create Analysis/Graph Macro submenu, select Basic Statistics/Tables.

Classic menus.  Right-click on the icon representing the current analysis on the task bar, and select Create Macro from the Analysis/Graph Icon shortcut menu.

Alternatively, with the analysis dialog box maximized, click the Options button and select Create Macro from the Options menu.

After you select this option, the New Macro dialog box is displayed. Call the new macro MyMacro. Click the OK button, and the new macro will be displayed in a Stand-alone window. Stand-alone macro programs have to be loaded before they can run, while Global macro programs (created by selecting Save as Global Macro from the File menu) become part of your STATISTICA program; that is, they will automatically be loaded the next time you run STATISTICA. Next click OK.

The resulting SVB program may seem a bit overwhelming at first. However, the structure of the program is rather straightforward (see also Some Common Elements of Recorded Macro (SVB) Programs). First there is the statement:

Set newanalysis = Analysis(scBasicStatistics)

Here the new analysis object is created of type Analysis with the parameter scBasicStatistics; this statement will display the Basic Statistics and Tables Startup Panel. Next, there is the block:

With newanalysis.Dialog

.Statistics = scBasDescriptives

End With

The With newanalysis.Dialog block is a shortcut method for setting the various properties available on the Startup Panel; in this case the only property is the Statistics property, which selects the Descriptive statistics option from the Startup Panel. The newanalysis.Run statement "clicks" the OK button, i.e., causes the program to proceed to the next dialog box. The next dialog block sets the many properties of the Descriptive Statistics dialog box.

With newanalysis.Dialog

.Variables = "1 2 3 4 5 6 7 8"


.CompressedStemAndLeaf = False

End With

Finally, at the end of the macro you have:

newanalysis.Dialog.Summary.Visible = True
newanalysis.Dialog.Histograms.Visible = True

These two lines select the Summary results spreadsheet and the Histograms option on the Normality tab (in a sense these commands "click" those buttons. Note that these commands are shortcuts for the more explicit code that would look like this:

Set r1=newanalysis.Dialog.Summary
r1. Item(1).Visible=True
j as Integer
j=1 To g1.Count


Next j

Instead, in the actual recording of the macro, these lines are contracted. First, remember that all results spreadsheets and graphs are returned as collections of objects, i.e., as arrays of spreadsheet objects, graph objects, or mixtures of both. Setting the .Visible attribute on the collection automatically makes all results objects in the collection visible. Second, the single line newanalysis.Dialog.Summary.Visible = True will automatically create the respective collection of results spreadsheets, and then set the .Visible attribute (for all objects in the collection).

To run this macro, press F5 or click the Run Macro button on the SVB toolbar.