Accessing Statistica Visual Basic Libraries

When "launching" a statistical analysis from within a Statistica Visual Basic program, the first thing to do is to create a new analysis object. If you want to launch a Statistica analysis from within Visual Basic of another application (e.g., Excel), then you first need to load the necessary Statistica libraries (often via an option called References on the Tools menu of the application's Visual Basic Editor), and, second, create an object of type Statistica.Application; you can then create analysis objects that are part of the Statistica.Application object.

So for example, to access the functions in the Statistica Basic Statistics library from within Microsoft Excel, you would include Visual Basic code like this:

Set x = CreateObject("Statistica.Application")
 Set a = x.Analysis(scBasicStatistics, _
 Path & "\Examples\Datasets\exp.sta")

Note: x now is an object of type Statistica.Application; a is an object of type Statistica.Application.Analysis. When you are running a program from within the Statistica Visual Basic (SVB) program editor, you can omit the explicit declaration of the Statistica.Application object, and simply write:

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

When you run the program from within Statistica, the program will "know" that the analysis object is part of the current Statistica.Application. However, if you want, you can also create a new Statistica.Application; for example try running the following program from within SVB:

Sub Main
 ' Launch a new application; assign the new
 ' application object to x.

Set x = New Application

' Declare variables (objects) so we can assign
 ' the input data Spreadsheet after we launched
 ' the application; note that we could also launch
 ' the Statistica Basic Statistics module with an
 ' optional data file name parameter; however, for
 ' illustration purposes we will maintain an explicit
 ' object for the Spreadsheet.

Dim InputDocument As StaDocuments
 Dim InputFile As Spreadsheet
 Set InputDocument=x.Spreadsheets

' Here the input data Spreadsheet is opened, and
 ' the newly opened document object assigned to
 ' variable InputFile.

Set InputFile=InputDocument.Open( _
 Path & "\Examples\Datasets\exp.sta")

' Next we launch the Statistica Basic Statistics
 ' module; note that we could have also launched it
 ' with an optional input data file parameter; i.e.
 ' Set a = x.Analysis(scBasicStatistics, _
 ' Path & "\Examples\Datasets\exp.sta")

Set a = x.Analysis(scBasicStatistics, InputFile)

' Make the application visible, the input data
 ' Spreadsheet visible, and the analysis (start-up
 ' dialog) visible.

InputFile.Visible=True
 x.Visible=True
 a.Visible=True

' Here we could add additional code to perform
 ' computations with this or other modules.
 End Sub

This program will create (launch) a new Statistica application; it will then open an input data file, and launch the Statistica Basic Statistics module. Finally, all objects declared in this program are made visible, so when it is done, you will see the new Statistica application, the input data file (spreadsheet), and the Startup Panel for the Basic Statistics module.