Macro (SVB) Programs Example - Statistica Dialog Box for Selecting Data Files

The Statistica Visual Basic language contains numerous functions for accessing Statistica specific user interface features. Note that these functions are specific to the StatisticaA user interface, and when you run Statistica from another application (e.g., from Microsoft Excel Visual Basic for Applications), these functions will not be visible to those programs. Likewise, user interface functions that are available inside the Visual Basic implementation of other applications are usually not available in Statistica Visual Basic. Therefore, when designing a Visual Basic program to run from a "foreign" application (e.g., from within Microsoft Excel), it is best to design the user interface (dialogs) using the tools available in that application; those tools are usually designed such that they allow you to program interfaces with an overall "look-and-feel" that makes them compatible with all other interfaces (dialogs) used in the respective application. Refer also to Custom Dialog Boxes; Custom User Interfaces for additional details.

Many of the Statistica specific user interface functions can be reviewed via the Function Browser.

The simplest way for a user to request an input data file (spreadsheet) is via the GetFilePath function. Here is a simple program that requests that the user select an input data file; the program will then open that file (input spreadsheet) and make it Visible.

Sub Main

Dim FileName As String

' Declare variable InputFile as a Spreadsheet object.
Dim InputFile As Spreadsheet

' Call the GetFilePath function to request that the user ' select an input data file.
FileName=GetFilePath(, "sta", , "Open Statistica data file" )

' If the user cancels out of the GetFilePath function, the ' length of the FileName that is returned will be 0; 
thus ' we can check here whether the user clicked Cancel; if ' so, we go to label Finish at the end of the program.
If Len(FileName)<1 Then GoTo Finish

' This statement will open the input data file, and assign ' the input Spreadsheet document to variable InputFile.
Set InputFile=Spreadsheets.Open(FileName) InputFile.Visible=True

Finish: End Sub

If you want to use the data file to run a particular analysis, for example, 
Basic Statistics, you can pass the data file name directly when you create the analysis object. 
For example:

Sub Main

Dim FileName As String

' Declare variable InputFile as a Spreadsheet object.
Dim InputFile As Spreadsheet

' Call the GetFilePath function to request that the user ' select an input data file.
FileName=GetFilePath(, "sta", , "Open Statistica data file", )

' If the user cancels out of the GetFilePath function, the ' length of the FileName 
that is returned will be 0; thus ' we can check here whether the user clicked Cancel; if 
' so, we go to label Finish at the end of the program.

If Len(FileName)<1 Then GoTo Finish

' create the Basic Statistics Analysis object
Set newanalysis = Analysis (scBasicStatistics, FileName)

' insert here the rest of the previously recorded program.... With newanalysis.Dialog
.Statistics = scBasDescriptives

End With Finish: 
End Sub
 

This example code illustrates the most efficient way to request an input file from the user and then proceed with the analysis by running the remainder of the previously recorded macro. Of course, you can in that case also request that the user select the variables for the analysis, from the user-selected data file.