The STATISTICA VB Object Model

The STATISTICA libraries contain all functions that allow you to fully program and customize your STATISTICA application; these functions can be called from other applications that support the standard Visual Basic language, such as Microsoft Visual Basic 6, Microsoft Excel, etc.

Example: A Simple SVB Program to Compute Descriptive Statistics
In STATISTICA, select File - New. In the Create New Document dialog box, select the Macro (SVB) Program tab, and create a macro called Example 1.

SVB is organized around analysis objects; for example, to run an analysis with the STATISTICA Basic Statistics module, you would first create an analysis object with the constant scBasicStatistics and (optionally) with a data file name (location of the file containing the input spreadsheet). To make access to the thousands of statistical functions and options available in the STATISTICA system as convenient as possible, SVB maintains a very close correspondence between the dialogs as they are presented during interactive analyses and the flow of the SVB program. In a sense, once an analysis has been created, such as the analysis via the Basic Statistics module in the example, you simply "program the dialogs" for the respective statistical analysis:  

Sub Main

' NOTE: The datafile may reside in a different directory on
 ' your installation.  Also, if you recorded this portion of
 ' the code via a Master Macro [option Tools - Macro - Start
 ' recording of log of analyses (Master Macro) ], consecutive
 ' analyses would be enumerated as newanalysis1, newanalysis2,
 ' etc., and the input datafile spreadsheets would be explicitly
 ' assigned to variables (objects) S1, S2, etc.

Set newanalysis = Analysis (scBasicStatistics, _
 Path & "\Examples\Datasets\exp.sta")

newanalysis.Dialog.Statistics = scBasDescriptives
 newanalysis.Run
 newanalysis.Dialog.Variables = "1-8"

' NOTE: the following line illustrates the simplest way to
 ' produce a visible results spreadsheet; when recording
 ' macros from analyses, various additional system settings
 ' (e.g., output options) are also recorded, and results
 ' spreadsheets and graphs are typically handled via the
 ' RouteOutput method.

newanalysis.Dialog.Summary.Visible = True

End Sub

Organization of SVB programs
As you can see in the Example: A Simple STATISTICA Visual BASIC (SVB) Program, SVB is organized around analysis objects; for example, to run an analysis with the STATISTICA Basic Statistics module, you would first create an analysis object with the constant scBasicStatistics and (optionally) with a data file name (location of the file containing the input spreadsheet). To make access to the thousands of statistical functions and options available in the STATISTICA system as convenient as possible, SVB maintains a very close correspondence between the dialogs as they are presented during interactive analyses and the flow of the SVB program. In a sense, once an analysis has been created, you simply "program the dialogs" for the respective statistical analysis. Put another way, if you were to do the analysis by hand, then after invoking the Basic Statistics module, you would follow through a sequence of dialogs to specify the desired analysis.

You can think of each dialog as a property of the (e.g., Basic Statistics) analysis, and of each option, selection, etc. on that dialog as a property of that dialog. Thus, you first invoke a module by declaring the respective analysis object, and then set the desired options etc. as properties of the analysis (and the dialogs of that analysis). Note that when designing actual programs, the automatic macro recording facilities of STATISTICA do most the programming work for you. You simply run the desired analyses interactively, and then create the macro for those analyses; that macro will contain all of the programming code to recreate the analysis step by step, and it can easily be edited (copied, pasted) to create the desired customized application.

Moving between implied dialogs of the statistics module
To move from one dialog box to the next when running STATISTICA interactively, click OK (to move forward to the next dialog box) and Cancel (to return to the previous dialog box). SVB has two methods to accomplish this that belong to the Analysis object: Run (to move forward to the next dialog box) and GoBack (to return to the previous dialog box). Of these, only the Run method is illustrated in the simple example.
Creating output documents
Most results from STATISTICA analyses are presented in results spreadsheets and graphs. When running STATISTICA interactively, you create results spreadsheets and graphs by clicking the respective buttons in the analysis dialog boxes. In SVB, each results "button" can be (implicitly) clicked by executing the respective method that is part of the respective dialog. For example, every results dialog box in STATISTICA has a Summary button (identified by the icon) to create the most "important" results from the respective analysis. In SVB, every results dialog box has a Summary method to do the same.
Results spreadsheets and graphs
Each method that can be used to produce results spreadsheets and graphs (e.g., the Summary method) will return a collection of spreadsheet objects, graph objects, or spreadsheet and graph objects (see also Recording Simple Macro (SVB) Programs, Documenting an Analysis; Editing and Customizing Recorded Macro (SVB) Programs). Note that even if the respective results spreadsheet or graph consists of only a single document, it will still be returned as a collection. Thus, you can use the standard Visual Basic conventions to retrieve individual objects from the collection, etc.
RouteOutput method, and AnalysisOutput objects
When running STATISTICA interactively, the output spreadsheets and graphs can be sent to workbooks (by default), stand-alone windows, reports, etc., depending on the selection of options in the Analysis/Graph Output Manager. The choices of options in that dialog box are implemented by the AnalysisOutput object, which can be used as a "container" for the results spreadsheets and graphs. Typically, a summary results spreadsheet or graphs collection would be recorded as:

newanalysis.RouteOutput(newanalysis.Dialog.Summary).Visible=True

The RouteOutput method takes as an argument the Summary collection (of spreadsheets, graphs, or both) and places it into the workbook, report, etc. depending on the current selections on the Analysis/Graph Output Manager. The RouteOutput method actually returns an object of type AnalysisOutput which itself has a number of methods and properties to make it fully "programmable."

Note: the actual selections in the Analysis/Graph Output Manager are recorded via the OutputOption object. Specifically, those options will be recorded either as part of Analysis Macros if they are set or changed via Options - Output for the specific analysis, or they will be recorded as part of Master Macros if they are set or changed in a specific analysis as well as via the Output tab of the Options dialog box (accessed from the Tools - Options menu).
Case selection conditions, weights
When recording a sequence of analyses with different files, case selection conditions, case weights, etc., long sequences of SVB program instructions will be generated to reflect the settings and choices in successive analyses. When you play back such macro recordings, identical analyses will be performed; however, there is an important consideration to remember, or else results produced by a recorded macro can be different from those of the interactive analysis. Case selection conditions and weights that are defined for the input data file are a property of the input file (document) and not the analysis, and as such, they will not be recorded (a warning message will alert you to this fact whenever you define, for example, case selection conditions for an input data file), unless you recorded an Analysis Macro and specified the case selection conditions or case weights from an analysis dialog (via the Select cases or Weights buttons), i.e., not via Tools - Selection conditions or Tools - Weight, or you recorded a Master Macro and specified the case selection conditions or case weights either from an analysis dialog or via the Tools menu commands after you started the Master Macro recording (via Tools - Macro - Start Recording Log of Analyses (Master Macro).

In other words, case selection conditions or case weights defined for a data file can be thought of as the actual data (numbers) themselves, i.e., they "belong" to the data file and describe the nature of the data (instead of the nature of a specific analysis). So, for example, when you want to create a recording to document a particular analysis that produced specific results, you may want to explicitly set any case selection conditions or case weights as part of your analyses to ensure that they are properly recorded.

Manipulating and editing STATISTICA documents. Spreadsheets and graphs are only two of the document types that STATISTICA uses to handle input and output of statistical analyses. Other document types are (text) reports and workbooks, in which you can organize and manage all other documents. There are a large number of properties and methods available for each of these types of documents that you can use to customize your results or to access aspects of your results for further processing.