StatSoft Home Page
What Is STATISTICA Visual Basic (SVB)?
What Are Some of the Applications of SVB?
I Know Nothing about Visual Basic or Programming; Where Do I Start?
How Do I Access SVB?
What Does a Simple SVB Program Look Like?
What Is Meant By the Term "Object Model?"
What Are Properties, What Are Methods?
How Can I Record My Analysis in an SVB Program?
How Can I Record an Alaysis Macro?
What Exactly Is Recorded in Analysis Macros?
How Can I Record a Master Macro (Log of Analyses)?
What Exactly Is Recorded in Master Macros?
How Do I Execute an SVB Program from within STATISTICA?
How do I Speed up the Execution (Loading) of SVB programs?
What Are the Major "Components" in a Typical SVB Macro Program?
How Are Case Selection Conditions and Case Weights Handled in Recorded Macros?
How Are Output Options Handled in Recorded Macros?
What Data Types Are Supported in SVB?
How Do I Assign a Value to a Variable?
What Are Collections?
How Do I Specify a Condition Instruction (If ... Then)?
How Do I Execute an Expression in a Loop?
I Already Know about Visual Basic; Does SVB Support Advanced Language Features?
What Are Subroutines and Functions?
What Is the Difference between Passing Variables to Subroutines and Functions By Value and By Reference?
What Are Local Variables vs. Global Variables?
Can I Define My Own Class Modules and Object Modules?
Can I Expand My SVB By Calling External DLLs?
Does the SVB Environment Provide Tools for Debugging?
How Can I Get On-Line Help?
What Is the Function Browser?
How Are Errors Handled During the Execution of an SVB Program?
How Are Non-Fatal Errors (Warnings) Handled During the Execution of an SVB Program?
Does SVB include a "Dialog Painter"?
How Is SVB Integrated with STATISTICA Data (Input), Analyses and Output?
What Are the Names for the STATISTICA Reference Libraries (Modules)?
How Can I Access Results Spreadsheets, Graphs, Workbooks, Etc.?
How Can I Create a Blank Graph, and Set Data Directly into the Graph?
What Is the RouteOutput Method, What Is the AnalysisOutput Object?
What Kind of Output Can I Create with SVB?
How Can I Change the Font (or Other Aspects) of Numbers in Spreadsheets?
How Can I Modify the Appearance of Graphs (e.g., Axis Labels) from within SVB?
How Can Other Aspects of Graphs Be Modified?
Can I Use SVB to Develop "Extensions" of STATISTICA and My Own New "Modules?"
How Can I Attach a Macro Program to a Toolbar Button (Keyboard Command, or Menu Option)?
Can I insert ActiveX controls into my graphs?
Can I Execute an SVB Program from within Other Visual Basic Compatible Applications?
How Can I Run a STATISTICA Analysis from Microsoft Excel?
What Is the Capacity of SVB, and Can It Handle Large Computational Problems?
Does SVB Support Matrix Operations?
How Can I Use the Data in a Spreadsheet with Matrix Functions? (How Do I Copy Data Efficiently from Spreadsheets to Matrices, and Back?)
Can I Create Custom Dialogs and Other Interactive User Input Controls in SVB?
How Are the Different Controls in Custom Dialogs "Serviced?"
What Is STATISTICA Visual Basic (SVB)?
The industry standard STATISTICA Visual Basic language (integrated into STATISTICA) offers incomparably more than just a supplementary application programming language (that can be used to write custom extensions). STATISTICA Visual Basic takes full advantage of the object model architecture of STATISTICA and allows you to access programmatically every aspect and virtually every detail of the functionality of the program. Even the most complex analyses and graphs can be recorded into Visual Basic macros and later be run repeatedly or edited and used as building blocks of other applications. STATISTICA Visual Basic adds an arsenal of more than 10,000 new functions to the standard comprehensive syntax of Microsoft Visual Basic, thus comprising one of the largest and richest development environments available.
What Are Some of the Applications of SVB?
There are countless applications for STATISTICA Visual Basic ranging from recording simple macros to automate routine tasks, to the development of large scale, powerful applications that take full advantage of advanced technologies offered in STATISTICA. The following is a selection of examples.
I Know Nothing about Visual Basic or Programming; Where Do I Start?
Visual Basic is a powerful industry standard language that will allow you to develop custom programs using the features of many (compatible) standard application programs, such as Microsoft's office programs (Word, Excel, Access, etc.), and of course STATISTICA. Depending on your aspirations as a programmer, you may want to pursue a more systematic approach to learn the language or start by modifying ready examples, to suit your particular needs.
1. Learning Visual Basic - "becoming an expert." If you want to learn systematically about the Visual Basic language from the ground up, so to speak, we would recommend that you begin by studying a general introductory book or course on the subject. You will find in your local bookstore entire bookshelves filled with books on Visual Basic; also, your local college or university will most likely offer introductory courses on this language. Such courses are very useful because they will allow you to familiarize yourself with basic programming concepts, and how to take advantage of many features of the language to build truly sophisticated custom applications.
2. Learning by examples and from recorded macros - "using SVB occasionally." If you have had some exposure to programming in Visual Basic or other languages, you will find many of the features of STATISTICA Visual Basic very familiar. You may want to read this documentation, try the numerous examples that illustrate various features of the language, and modify them to suit your needs. By running various interactive analyses, and recording them into STATISTICA Visual Basic program macros, you will quickly gain a working knowledge of the STATISTICA object model; also, much of the program code that is often needed can be generated by recording macro programs, and combining them into sophisticated custom applications.
3. Editing recorded macros - "no experience necessary..." Finally, if currently all your applications for STATISTICA Visual Basic are limited to occasionally rerunning analyses using different variables or different datasets, then you can simply look into the SVB scripts that are automatically recorded by STATISTICA when you perform any analysis and identify places where datafile names and variable names are entered. All you need to do is to edit them (or replace with new ones) and run the respective macros. This simple method requires very little knowledge of the STATISTICA Visual Basic syntax conventions.
How Do I Access SVB?
STATISTICA Visual Basic is accessible from the Statistics menu or by selecting New from the File menu (then select the Macro (SVB) Program tab on the Create New Document dialog). To open a previously saved STATISTICA Visual Basic program, select Open from the File menu. You can open multiple SVB programs at a time. For example, you can have five or more different programs opened in their separate windows and cut and paste the code between the programs or execute them in arbitrary sequences. SVB comes with an integrated environment that allows you to write, edit, verify, debug (i.e., "dry run"), and execute your programs.
What Does a Simple SVB Program Look Like?
The following program illustrates various general features of the Visual Basic (VB and SVB) language in a simple program. In STATISTICA, select New from the File menu, then select the Macro tab and create a macro called Overview 1.
Sub Main
To run this program, press F5 or select Run Macro from the Run menu. This program will display two message boxes: the first one shows an OK button and a Cancel button, and the next one will show a message depending on which button you clicked.
' Bring up a Message Box, with the Ok and Cancel buttons,
' and with the following text;
' note the continuation symbol _ (underline) at the
' end of the first line, to allow the single statement
' to span two lines
If MsgBox ("Hello! Click OK or Cancel", _
vbOkCancel)=vbOK Then
MsgBox "You clicked OK"
Else
MsgBox "You clicked Cancel"
End If
End Sub
What Is Meant By the Term "Object Model?"
The power of Visual Basic in general, and of STATISTICA Visual Basic in particular, derives from its ability to access the features of various programs that support the Visual Basic language. For example, you can write a program that produces a results spreadsheet via STATISTICA and pastes that spreadsheet into a Microsoft Word document and a Microsoft Excel spreadsheet. That same program can then access individual cells in the spreadsheet, either in Microsoft Excel or STATISTICA, format those cells so that the contents of some cells are displayed in a different color (e.g., significant results are shown in yellow), and save all results (the document, spreadsheet, and Excel spreadsheet) to a disk. In this case you would access from a single Visual Basic program features in three different applications: STATISTICA, Microsoft Word, and Microsoft Excel.
The way this is generally accomplished is by organizing the respective features and functions available in an application by objects. For example, the STATISTICA application is an object of type Application.
For example, a property of a STATISTICA application is whether or not it is visible on the screen (property Application.Visible = True or Application.Visible = False). Another property of the application object is the currently active analysis (Application.ActiveAnalysis) or active dataset (Application.ActiveDataSet). There are also methods available that perform various operations on the object or inside the object. For example, the Application object contains a method to open a datafile (input spreadsheet).
Some of the properties are themselves different types of objects, with many properties, methods, and other objects. For example, the ActiveDataSet property can be assigned to an object of type Spreadsheet. The Spreadsheet object has many properties itself; among them is the Range property, which can be assigned to an object of type Range. The Range object has many properties, among them the Font property. The Font property can be assigned to an object of type Font, which has properties like Name (of the font), Bold, Italic, etc. So, by setting, for example, the Bold property of the Font object to True, you can format to bold type the contents of a cell range in a spreadsheet in a STATISTICA application.
In general, objects are hierarchically organized, and when you want to access a particular feature of the program (e.g., change the font in a spreadsheet cell), you need to access the proper object by "stepping" through the hierarchy of objects (e.g., from the STATISTICA Application, to the Spreadsheet, to the Range object, to the Font object). So part of learning to program in (STATISTICA) Visual Basic is to gain a good working knowledge of the hierarchical object model. Fortunately, the objects in STATISTICA Visual Basic are logically organized, and can be reviewed via the Object Browser.
The Object Browser is displayed by clicking the Object Browser button (on the Macro toolbar) or by selecting Object Browser from the View menu.
Whare Are Properties, What Are Methods?
As described in the context of the description of the Object Model (What Is Meant By the Term "Object Model?", page 939), once an object has been created, the Visual Basic program then has access to the properties and methods contained in that object. Properties can be mostly thought of as variables, methods can be mostly thought of as subroutines or functions that perform certain operations or computations inside the respective application object.
How Can I Record My Analysis in an SVB Program?
There are three categories of macros that can be automatically created as you run STATISTICA:
How Can I Record an Analysis Macro?
Here is an example of how you can record a STATISTICA Visual Basic Analysis Macro program.
Start STATISTICA and open the example datafile Exp.Sta. Select Basic Statistics from the Statistics menu. Click the OK button, and on the Descriptive Statistics dialog, click the Variables button and select all variables; then click the Summary button to produce the results spreadsheet. Next, do one of two things: Either right-click on the minimized ("iconized") Descriptive Statistics dialog and select Create macro from the resulting shortcut menu, or maximize the Descriptive Statistics dialog again, and select Create macro from the Options button menu. On the New Macro dialog, specify a name, and click the OK button.

If you run this program, the identical analysis is performed, i.e., the macro program will create a summary results spreadsheet with descriptive statistics for variables 1 through 8 in the currently active datafile; if the currently active datafile is Exp.sta, then the summary results spreadsheet will be performed for all (8) variables in that datafile.
What Exactly Is Recorded in Analysis Macros?
Analysis Macros are the ones that are created automatically and are always being recorded "behind the scenes" whenever you start an analysis from the Statistics or Graphs menus. The term "analysis" in STATISTICA denotes one task selected either from the Statistics or Graphs menu, which can be very small and simple (e.g., one scatterplot requested from the Graphs menu) or very elaborate (e.g., a complex structural equation modeling analysis selected by choosing that option from the Statistics menu and involving hundreds of output documents).
Whenever you choose any options from those menus, recording begins; the recording terminates when you exit the analysis, that is, when you click the final Cancel button to close the startup dialog. At that point, the recording is discarded and "forgotten." There are several things to remember when using the Analysis Macro recording facilities. All of these are consequences of the general "rule": Only actions performed as part of and during the specific analysis being recorded will be reflected in the Analysis Macros.
Datafile selections and operations. The recording of Analysis Macros begins automatically whenever a new analysis is started from the Statistics or Graphs menu. Anything that "happened" before that is not recorded in the Analysis Macro. Thus, your specific selection of the input datafile is not recorded (the Analysis Macro always assumes that it is to be executed on the current active input datafile) unless that choice is made by clicking the Open Data button on the respective analysis dialog. Neither are any operations recorded that you may perform on the input datafile, such as sorting the data, subsetting of variables and/or cases, etc.
Case selection conditions, case weights. Case selection conditions and case weights are only recorded if they are specified as part of the specific analysis, by clicking on the Select Cases or Case Weights button of the respective analysis; they will not be recorded in Analysis Macros if they are specified via the respective Tools menu options for the input datafile (or if they have been specified prior to the current analysis for the respective input datafile). Note that in STATISTICA, case selection conditions and case weights can be specified either (a) relatively permanently for input datafiles and automatically stored with the files, in which case they will automatically be used by all analyses based on the input datafile, or (b) they can be specified on a per-analysis basis, in which case any new (subsequent) analyses will not use those specifications. In a sense, when you specify case weights or case selection conditions to "belong" to the datafile, those specifications become part of the datafile just like the data (numbers) themselves; when you specify case selection conditions and case weights for a particular analysis, those specifications are only applied to the respective analysis. To reiterate, case selection conditions and case weights are only recorded in Analysis Macros if they are specified via the respective analysis options (buttons), and regardless of whether or not they are specified for the current analysis only, or as a "permanent feature" of the datafile.
Changing current datafile selection conditions and weights. Because case selection conditions and case weights can be recorded into Analysis Macros, in the exact same manner as specified via the Analysis/Graph Case Selection Conditions and Analysis/Graph Case Weights dialogs (when accessed via the respective buttons of the current analysis dialog), it is possible to reset the "permanent" current datafile selection conditions and weights by running an Analysis Macro. If you run an Analysis Macro that changes the case selection conditions for the current input datafile, then all subsequent analyses will use those specifications, and the results of those analyses will be affected accordingly.
Handling output: Sending results to workbooks, reports, etc. Like case selection conditions or case weights, the selections of output options (specifications) on the Output Manager are only recorded if they are made from the respective analysis that is being recorded (via the Output options on the respective analysis Options menu); changes in the Output Manager are not recorded if they are made globally for all analyses via the Tools - Options menu. In keeping with the logic of Analysis Macros, only actions that are performed as part of a specific analysis are recorded. For example, if you recorded an Analysis Macro without making any changes (from that analysis, via the Options - Output option available on every dialog of the analysis), then no information about specific settings of output options will be recorded. Consequently, when you run the macro, the output will be directed to the place(s) specified by the current default settings for the output. So, for example, while during the recording of a macro, results spreadsheets might have been directed to individual spreadsheet windows; when running the macro, and while different defaults are in place, the results spreadsheets might be directed to workbooks and report windows.
How Can I Record a Master Macro (Log of Analyses)?
In a Master Macro several consecutive and simultaneous analyses can be recorded (e.g., an analysis via Multiple Regression, followed by an analysis of the prediction residuals via Basic Statistics); also, most data management operations are recorded.
Here is an example of how you can record a STATISTICA Visual Basic Master Macro program - to create a complete log of all analyses from the point when you explicitly begin the Master Macro recording to the point when you terminate the recording. Remember that in Master Macros, basically all actions are recorded, including the specific datafile that is used for the analysis. Start STATISTICA and start the recording of the Master Macro by selecting Recording Keyboard Macro from the Tools - Macro menu; you will see the floating Record toolbar as a reminder that a recording "session" is in progress. Next, open the example datafile Exp.Sta. Select Basic Statistics from the Statistics menu. Click the OK button, and on the Descriptive Statistics dialog, click the Variables button and select all variables; then click the Summary button to produce the results spreadsheet. Next click on the stop button on the floating Record toolbar or select Stop Recording from the Tools - Macro menu, to create the SVB program of this analysis.
Note that, unlike in the Analysis Macro shown earlier, in this case the opening of the input datafile for the analysis was explicitly recorded. If you run this program, the identical analysis is performed, i.e., the macro program will create a summary results spreadsheet with descriptive statistics for variables 1 through 8 from datafile Exp.sta.
To reiterate, Master Macro recordings will record entire sequences of analyses, including the selection of various global (e.g., output) options, etc. You can even record a macro of sequential analyses where some analysis is performed on a results spreadsheet created by a preceding analysis (e.g., make some custom Scatter Icon Plots for residuals computed by Multiple Regression).
What Exactly Is Recorded in Master Macros?
Datafile selections. The recording of the Master Macro begins when you select Start Recording Log of Analyses (Master Macro) from the Tools - Macro menu. If you select an input datafile after you start the recording, then the selection of that file will become part of the Master Macro. For example, suppose you opened a file and then started a Multiple Regression analysis; the recorded macro would include the following lines:
How Do I Execute an SVB Program from within STATISTICA?
To run a STATISTICA Visual Basic program from within STATISTICA, in the currently active STATISTICA Visual Basic program editor, either press F5 or select Run Macro from the Run menu.
How Do I Speed up the Execution (Loading) of SVB Programs?
When you create STATISTICA Visual Basic programs, either by recording a macro from an interactive analysis, or by selecting the New option from the File menu, then by default the new program is initialized so that it can automatically use all of the procedures (statistical analysis routines, graphics routines) of your STATISTICA installation. Thus, you can access the complete functionality of all STATISTICA libraries in the new program. However, most if not all (completed) STATISTICA Visual Basic programs will only use a small portion of that functionality, and by removing the support for functions that are not needed, the execution of the program, or more specifically, the time required to load and initialize the program, can sometimes be speeded up significantly. Therefore, when designing programs for routine use, or for distribution, it is recommended to remove the references to STATISTICA libraries that are not required for the program's operation.
Removing unnecessary references. The functionality of STATISTICA is organized into several reference (or type) libraries that contain the functions, variables, etc. for the respective routines. You can review the reference libraries loaded for a current STATISTICA Visual Basic program (displayed in the program editor) by selecting option References from the Tools menu. Since most programs will only use a very small portion of the complete STATISTICA Visual Basic functionality, you can "unload" the unnecessary (unused) libraries by deselecting them in the References dialog (uncheck the respective checkboxes). Note that you can also change the default libraries that are loaded whenever you create a new program on the Macros (SVB) Programs tab of the Options dialog (choose the Edit option in the Type Library References box).
In most cases, the reference libraries required to execute a particular program are fairly obvious: If you use functions from the Graphics library then that library will be required for the program to execute properly. If you happen to make a mistake, and accidentally remove the reference for a required library, then the program will simply not run, and usually report an invalid property, method, or type of object in the place where a particular function call etc. was unresolved.
Technical note: How type library references are stored in .svb and .svx files. In some cases you may want to directly remove certain or all type libraries form a STATISTICA Visual Basic program without going through the References dialog. The actual references to the different STATISTICA type libraries are stored at the beginning of each .svb or .svx file. If you open such files as text files in a standard word processor or text editor, you will see references like this:
'#Reference {C9E5900E-3D45-11D4-9FF4-00C04FA0D540}#1.0#0#
'#Reference {C9E59002-3D45-11D4-9FF4-00C04FA0D540}#1.0#0#
These codes are the unique ID numbers that identify each type library in your system. The STATISTICA Visual Basic editor will not show these lines (of code), but instead interpret them as instructions to load the respective libraries. You may consult Microsoft system programming documentation for further details regarding these ID's, and advanced programmers may remove or add these ID's directly via a text editor, although this would not be the recommended procedures as it is more error prone.
What Are the Major "Components" in a Typical SVB Macro Program?
When you record a macro program from an interactive analysis, you will notice several common components of the programs. STATISTICA Visual Basic 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 datafile 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, STATISTICA Visual Basic maintains a very close correspondence between the dialogs as they are presented during interactive analyses, and the flow of the program. In a sense, once an analysis has been created, such as an analysis via the Basic Statistics module, you simply "program the dialogs" for the respective statistical analysis.
Here is a brief breakdown of the components of a (typical) Analysis Macro program, recorded via Basic Statistics Descriptive Statistics.
First, there is the statement:
How Are Case Selection Conditions and Case Weights Handled in Recorded Macros?
It depends on whether you are recording a Master Macro or an Analysis Macro. The general rule is that case selection conditions and case weights specified via the Select Cases or Case Weights buttons in a specific analysis are recorded into the respective Analysis Macro as well as the Master Macro (if one is being recorded at the time); when case selection conditions or case weights are changed from the Tools menu, then those changes are only recorded in Master Macros.
How Are Output Options Handled in Recorded Macros?
It depends on whether you are recording a Master Macro or an Analysis Macro. Like with case selection conditions and case weights, if the Analysis/Graph Output Manager is brought up via the Output option for a specific analysis from the Options menu (of the respective analysis dialog), then the choices on that dialog will be recorded into the respective Analysis Macro as well as the Master Macro (if one is being recorded at the time); when output options are changed by choosing Tools - Options, and then the Output Manager tab, then any changes made to the output options are only recorded in Master Macros.
What Data Types Are Supported in SVB?
STATISTICA Visual Basic supports several data types including Double, Integer, Long, Boolean, String, Variant, and Object.
The Double data type and the Integer and Long data types are probably the ones most commonly used in computations. Variables declared as Double can hold (store) real numbers, approximately in the range from +/-1.7E +/- 308 (approximately 15 digits of precision); variables declared as Integer can hold (store) integer numbers in the range from -32,768 to 32,767, and Long variables can hold (store) integer numbers in the range from -2,147,483,648 to 2,147,483,647; other common data types are Boolean (True [1] or False [0]) and String (a string variable of arbitrary length). Refer to the Electronic Manual for a description of all data types.
Declaring variables. Variables should be declared at the beginning of each program by using the dim command; for example:
How Do I Assign a Value to a Variable?
Here are examples of simple declarations of variable types, and how to assign values to them:
What Are Collections?
A collection is very similar to an array; however, the collection is an object with various methods that in many instances make dealing with a collection much more convenient than dealing with an array. In STATISTICA Visual Basic, all results spreadsheets and graphs from analyses are returned as collections, which makes the programmatic editing, storing, and further processing of results very convenient.
How Do I Specify a Conditinal Instruction (If ... Then)?
The following program illustrates various general features of the Visual Basic (VB, and SVB) language including a conditional instruction.
How Do I Execute an Expression in a Loop?
Here is an example of a simple (For...Next) loop. The loop is used to fill array x with values between 1 and 10.
I Already Know about Visual Basic; Does SVB Support Advanced Language Features?
STATISTICA Visual Basic is an advanced programming environment that allows experienced programmers to build large and complex custom applications. Support is provided for subroutines and functions, as well as user-defined class modules and object modules.
What Are Subroutines and Functions?
Typically, complex applications written in STATISTICA (or any other) Visual Basic are structured. In other words, most programs will not consist of a single routine, but of many separate routines that will call each other. Every macro program consists of a Main program inside a Sub Main ... End Sub block. Inside the main program you can call subroutines and functions to perform repetitive tasks, or just to keep the structure of your program transparent. Here is an example program that consists of several subroutines and functions; note that the main program performs no computations, and only contains calls to the subroutines.
What Is the Difference between Passing Variables to Subroutines and Functions By Value and By Reference?
If you want to pass a variable to a subroutine, run computations on it, and alter its contents, then the variable must be passed by reference (this is the default method how arguments are passed to subroutines or functions). Essentially, passing a variable by reference means passing the variable itself to the subroutine, and any changes made to it in the subroutine will be permanent. By contrast, if you want to pass a variable, run computations on it, and alter the temporary instance of it within the subroutine without affecting the original variable, then you must pass the variable by value. When a variable is passed by value to a function or subroutine, only a copy of the variable is passed, not the actual variable. If any changes are applied to the variable within the called function, then those changes will only pertain to the copy of the original variable. When passing a variable by value, its value will always be preserved, no matter what is done within the called function. To illustrate, instead of making ComputeSumOfSqrs in this example a function, we could make it a subroutine and pass the variable SumValue as an argument by reference; by using this approach, SumValue will be directly altered by the subroutine without needing to return a value. Note that the ByRef keyword in the example below would be optional, since the default method of passing arguments to subroutines or function is by reference.
What Are Local Variables vs. Global Variables?
Variables declared in a Visual Basic program are visible (i.e., they can be referenced) inside the "scope" where they are defined. The scope is the program unit inside of which the variable is defined. For example, variables declared inside a subroutine are only visible inside that subroutine. Variables declared outside any routines, before any program code, are visible to all subroutines and functions in the same file. In the programs shown below, variable a is either defined inside the Main routine, and then must be passed to the subroutine that displays its value, or it is declared as a global variable, outside the Main routine, in which case it is visible in all subroutines and functions in the same file.
Here is a simple program, where the variable must be passed, because it is defined only inside the scope of the Main program.
Can I Define My Own Class Modules and Object Modules?
STATISTICA Visual Basic supports class modules and objects modules. A discussion of classes and objects and the advantages (and some disadvantages) of object-oriented programming is beyond the scope of this introductory documentation; you should consult more advanced general sources on Visual Basic for details. In general, when developing large projects in Visual Basic, it is advantageous to impose as much structure on the program as possible, i.e., to break it down as much as possible into smaller functional units. This can be accomplished to a large extent by subroutines and functions; however, another way is by defining classes.
For example, you may want to use in your computations some highly customized way in which to compute some statistics to denote the central tendency for a dataset. One such statistic is, for example, the mean, but there may be additional considerations and problems that preclude you from using the simple arithmetic mean (e.g., censoring, missing data, highly skewed distributions, invalid data ranges, etc.). You may want to define a separate set of routines, options, etc., to compute the central tendency of a dataset. One way to do this is to create a class that contains the respective functions, subroutines, variables, etc. This class could for example compute the central tendency in one variable (e.g., variable CentralTendency), and the method that was used as a name in another variable (e.g., variable MethodName).
One of the advantages of using classes, as opposed to simple subroutines and functions, is that you can program all "things" related to the central tendency measure in a separate file. In the actual program, you would always access a variable called CentralTendency; even if the method for computing the central tendency is refined or variables are added to the class, etc., you don't have to rewrite the code that uses these measures at all. In other words, the class itself can be modified or refined, or another team of programmers could develop it, while the programs that use the class do not have to be modified at all.
Classes vs. objects. The difference between classes and objects is that classes have to be explicitly declared (instantiated) in the program that uses them, while objects are automatically instantiated and available at all times. Both of these will be illustrated in a simple example below.
The asterisk (*) convention: Writing portable programs. When writing programs that include classes or objects, and that are to be deployed on other computers you can use the asterisk (*) convention to access the include files that contain the classes and objects. Specifically, after you wrote (defined) your class or object modules, save them either in the directory where STATISTICA is installed (where the STATISTICA executable programs are located), in the directory where the current module is running from (if it has been saved), or in the global macro directory. To access modules from within an SVB program, you can then use, for example, #Uses "*MyClassModule.svc", to access the previously saved class module MyClassModule.svc, and you do not have to use the explicit reference to the respective directory (e.g., #Uses "J:\STATISTICA\Examples|Macros\MyClassModule.svc"). Thus, by using the asterisk (*) convention with the #Uses or $Include directives.
A simple example. Suppose you wrote a program to retrieve some keys (key-codes) or passwords to gain access to particular datafiles or programs. The main program does nothing else but access the class (or object) that generates those keys. The method in which those keys are computed is entirely "encapsulated" inside the respective class (or object).
Create the following three files as STATISTICA Visual Basic macro programs. The first one defines Class as the Module Type (when creating the new Visual Basic document); call this program KeyCodesClass. The screen below shows the selections from the Create New Document and the Module Type dialogs to create the KeyCodesClass module.
The second file defines Object as the Module Type; call this program KeyCodesObject. As a third file, create a standard STATISTICA Visual Basic macro program, and call it RetrieveKeyCodes; note that only this latter program will automatically have the Sub Main ... End Sub declarations inserted into the code.
Now enter the following code into these programs:
The Class Module: KeyCodesClass
Can I Expand My SVB By Calling External DLLs?
There are two ways in which you can access external libraries from STATISTICA Visual Basic. The first method is the easiest, but relies on the external DLL's compliance with Visual Basic standards. In other words, if the external DLL (program) supports Visual Basic (e.g., such as Microsoft Excel), you can select Tools - References from the STATISTICA Visual Basic toolbar to load the respective libraries. The objects, functions, methods, etc. in that library are now accessible like all STATISTICA Visual Basic functions. So you could, for example, create from within STATISTICA Visual Basic an Excel Spreadsheet, perform some spreadsheet operations and computations, and then transfer the results back to a STATISTICA Spreadsheet (e.g., via the .Copy and .Paste methods).
Writing your own DLLs, or accessing "exported" functions in external DLLs. You can also access "exported" functions or subroutines in other DLLs, even if they were not specifically designed to work with Visual Basic. For example, if you are an experienced C++ programmer, you may want to add some highly customized computational routines to your STATISTICA Visual Basic program. In a sense, this method of accessing "the outside world" would allow you to add custom program options to STATISTICA; for example, you may have a proprietary complex algorithm, implemented in a complete program (which includes its own user interface), for evaluating stocks based on historical data. You could write a STATISTICA Visual Basic program to put a new option on the Statistics menu to execute this program and call your custom program when this option is chosen.
There are a number of things to consider when writing your own DLLs that are to be called by STATISTICA Visual Basic, or when writing STATISTICA Visual Basic programs to access functions in such DLLs.
Declaration of functions and subroutines in the external DLL. SVB requires that the external DLL use the _stdcall calling conventions. This is true of all Win32 API calls (allowing them to be used directly from SVB), but when defining your own entry points in a custom DLL, care must be taken to make sure the export is defined correctly. Here are two prototypes of sample routines that could be called from SVB:
extern "C" int AFX_API_EXPORT WINAPI SampleFunction(int x);
extern "C" void AFX_API_EXPORT WINAPI SampleSubroutine(int q);
'where:
'extern "C" means this name is not "decorated" (as C programmers used to say) with C++ type information;
'AFX_API_EXPORT is defined to __declspec(dllexport), which tells the compiler to export 'this name;
'WINAPI is defined to __stdcall, meaning use "standard calling conventions."
Calling external functions and subroutines. To use these routines in STATISTICA Visual Basic, you need to "declare" them in the declarations area of your SVB program (before the first function is defined). Refer to the Electronic Manual for a full explanation of the Declare statement and its options. For example:
Does the SVB Environment Provide Tools for Debugging?
Once a macro program has been specified, the STATISTICA Visual Basic environment provides powerful methods for testing and debugging the program. You can set individual breakpoints in the program where you want the program to stop temporarily to allow you to look at the values of variables at that point (you can set and clear breakpoints by pressing F9 or by clicking the Toggle breakpoint toolbar button). You can step through the program by pressing SHIFT+F8 or clicking the Step over toolbar button.
Note that the variables in the Watch window (tab) not only can be observed, but they can also be changed interactively as the program is running.
How Can I Get On-Line Help?
The STATISTICA Visual Basic language contains ("understands") all standard Visual Basic language declaration, features, and functions, as well as more than 10,000 functions, declarations, statements, etc. that provide access to the STATISTICA functionality. To read more about a particular Visual Basic (non-STATISTICA specific) statement such as Dim, For...Next, etc., highlight the respective statement and press F1.
To learn how to access the STATISTICA specific functions and procedures, study the STATISTICA object model. The various features of graphs, spreadsheets, and reports are logically organized into hierarchies of objects. The objects representing the standard analyses (and graphs) are organized according to the "flow" of dialogs, as if you were performing an interactive analysis. This is best illustrated if you record an analysis in a STATISTICA Visual Basic macro program. Every dialog is a separate object, and all the options available on the respective dialogs are properties. In practically all cases, after you record a macro, you will be able to match the various properties that were recorded (for the different dialogs) with the detailed descriptions of the respective options in the context of the dialog help.
What Is the Function Browser?
There are numerous functions specific to STATISTICA, and generally only available in STATISTICA Visual Basic. These are extensions to the general Visual Basic language, such as probability functions, matrix functions (see also page 1000), simple user input dialogs, etc. You can review these functions in the Function Browser, which is accessible via the SVB View menu or by clicking the Function Browser toolbar button.

Shown below is a simple program that will "look up" the z value for p = .975.
How Are Errors Handled During the Execution of an SVB Program?
STATISTICA Visual Basic provides the same facilities for error handling as other general implementations of Visual Basic. Thus, detailed discussions on error handling can be found in the numerous general sources describing this programming language.
General Visual Basic errors, math errors, etc. A standard method for trapping general Visual Basic errors, such as math errors (e.g., division by zero), is to use the On Error Goto ... statement, to direct the program flow to a particular label in the program. Note that each subroutine and function should have its own On Error Goto statement. Here is a simple example program that will generate a division-by-zero math error.
How Are Non-Fatal Errors (Warnings) Handled During the Execution of an SVB Program?
In many instances throughout interactive analyses you may receive non-fatal error (warning) messages, for example, to inform you that some missing data were replaced by means, that some variables were dropped from the analyses, that some parameters were reset, etc. Usually, these warning will not require that the respective analyses be terminated, but the information provided in these warnings may be important for the user to be aware of.
When such warning messages occur during the execution of an SVB program, the Analysis Warning dialog will come up displaying the warnings that have occurred, when they occurred (the time and in which specific analysis), the approximate line numbers in the SVB program code where the warnings occurred, etc; if the respective non-fatal error, when it occurred during the interactive analysis, required some user response (e.g., Yes/No in response to a question whether or not to continue), then that user-input is also shown in the Message field.
This dialog will allow you to manage the warnings that occurred during your current "session" with STATISTICA (running SVB programs). Note that the warnings are collected across multiple analyses, and you can at any time create a Report of these analysis, send them to a Spreadsheet (so you can write SVB code to further process these messages), etc.
The GetAnalysisErrorReport method. When running STATISTICA analyses via Visual Basic from another application (e.g., from inside MS Excel), it can be desirable to deal with the warnings inside the other applications, without bringing up any STATISTICA specific dialogs. For example, you may want to place the warning messages into particular cells of an MS Excel spreadsheet. For that purpose, the Application object of STATISTICA contains a specific method:
Does SVB include a "Dialog Painter"?
Yes, a interactive dialog editor is included that allows you to build dialogs by dragging controls from a toolbar with the mouse.
How Is SVB Integrated with STATISTICA Data (Input), Analyses and Output?
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, Microsoft Excel, etc.
Organization of SVB programs. STATISTICA Visual Basic 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 datafile 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 an analysis via the Basic Statistics module, 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 will do most of 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 to the next when running STATISTICA interactively, you click the OK button (to move forward to the next dialog) and the Cancel button (to return to the previous dialog). SVB has two methods to accomplish this that belong to the analysis object: Run (to move forward to the next dialog) and GoBack (to return to the previous dialog).
Creating output documents. Most results from STATISTICA analyses are presented in results spreadsheets and graphs. When running STATISTICA interactively, you would create results spreadsheets and graphs by clicking on the respective buttons on the results dialogs. 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 in STATISTICA has a Summary button to create the most "important" results from the respective analysis. In SVB, every results dialog 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. 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 on the Analysis/Graph Output Manager dialog. The choices of options in that dialog 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 in an Analysis Macro or Master Macro as:
What Are the Names for the STATISTICA Reference Libraries (Modules)?
|
Module (Option) |
Library Name |
Symbolic Constant |
|
ANOVA* Basic Statistics Canonical Analysis Classification Trees Cluster Analysis Correspondence Analysis Discriminant Analysis Distribution Fitting† Experimental Design (DOE) Factor Analysis General CHAID Models General Classification and Regression Trees General Discriminant Analysis Models Generalized Additive Models Generalized Linear/Nonlinear Models General Linear Models General Partial Least Squares Models General Regression Models Log-Linear Analysis Multidimensional Scaling Multiple Regression Nonlinear Estimation Nonparametrics Principal Components and Classification Analysis‡ Process Analysis Techniques Quality Control Reliability/Item Analysis Survival Analysis Time Series Variance Components |
STAMANOVA STABasicStatistics STACanonical STAQuickTrees STACluster STACorrespondence STADiscriminant STANonparametrics STAExperimental STAFactor STAGCHAID STAGTrees STAGDA STAGAM STAGLZ STAGLM STAPLS STAGRM STALogLinear STAMultidimensional STARegression STANonlinear STANonparametrics STAFactor STAProcessAnalysis STAQuality STAReliability STASurvival STATimeSeries STAVarianceComponents |
scMANOVA scBasicStatistics scCanonicalAnalysis scClassificationTrees scClusterAnalysis scCorrespondenceAnalysis scDiscriminantAnalysis scDistributions scDesignOfExperiments scFactorAnalysis scGCHAID scGTrees scGDA scGAM scGLZ scGLM scPLS scGSR scLoglinearAnalysis scMultidimensionalScaling scMultipleRegression scNonlinearEstimation scNonparametrics scAdvancedPCA scProcessAnalysis scQualityControl scReliabilityandItemAnalysis scSurvivalAnalysis scTimeSeries scVarianceComponents |
How Can I Access Results Spreadsheets, Graphs, Workbooks Etc.?
The STATISTICA Visual Basic object model provides access to practically all aspects of STATISTICA analyses, and the results of those analyses. When you perform an interactive analysis, and record a macro program (see also How Can I Record My Analysis in a STATISTICA Visual Basic Program?, page 942), you will see that all of your output choices are recorded. The most important thing to remember is that all output spreadsheets and graphs are returned as a Collection of spreadsheet and graph objects respectively (see also What Are Collections?, page 957). You can retrieve and modify these objects in your program; for example, you can make the results (spreadsheet) of one analysis the input to the next analysis. Here is an example program:
How Can I Create a Blank Graph, and Set Data Directly into the Graph?
Practically all graphics options of STATISTICA are directly accessible via SVB; this makes SVB a very powerful graphics programming language. The following program shows how to create a blank 2D graph, set some data into the graph, and add an arrow.
What Is the RouteOutput Method, What Is the AnalysisOutput Object?
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 on the Analysis/Graph Output Manager dialog (accessed by selecting Output from the Options menu). The choices of options in that dialog 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:
What Kind of Output Can I Create with SVB?
There are a number of possible ways to display results, numbers, messages, etc. generated with a STATISTICA Visual Basic program. Most often, you will want to present results in spreadsheets, graphs, or reports. A very useful method for sending results spreadsheets and graphs to a current default "place" (workbook, stand-alone window, report) is to use the RouteOutput method described earlier (see page 979). However, you can also copy and paste results from STATISTICA into spreadsheets, text documents, etc., as long as those other types of output objects ("belonging" to other applications, such as Microsoft Excel or Word) support the Visual Basic standards.
Probably, the method you will most frequently use to display results is via spreadsheets and graphs; occasionally, you may also want to write some text or tables into a report. All of these are supported as objects, in the STATISTICA Visual Basic object model. For example, the following program will produce a spreadsheet, a line graph, and a report that will contain the spreadsheet and the line graph. All of these output objects will then be placed into a new workbook.
Note that the following program does not use the RouteOutput method (see page 979) to send the spreadsheet and graph to a default location (e.g., workbook) as currently defined via the Analysis/Graph Output Manager. Instead, the program illustrates how you can explicitly create spreadsheet and graph objects and move them to the location of your choosing.
How Can I Change the Font (or Other Aspects) of Numbers in Spreadsheets?
The functions in STATISTICA Visual Basic are organized in an intuitive hierarchical object model. The example program shown below illustrates the hierarchical nature of the objects, and the available respective methods and properties. Note that in order to review all available objects, methods, and properties, as well as constants that are recognized, you can always display the Object Browser.
The Object Browser can be displayed by clicking the Object Browser toolbar button (on the Macro toolbar), or by selecting Object Browser from the View menu.
Shown below is a simple example program that will change the font of the first column of the currently active input data spreadsheet to italics and bold.
How Can I Modify the Appearance of Graphs (e.g., Axis Labels) from within SVB?
The customization of graphs proceeds in much the same way as the customization of spreadsheets. After a graph object is created, various properties and methods are available to customize practically all aspects of the display. Here is an example of how to customize the font of the x-axis labels in a histogram:
How Can Other Aspects of Graphs Be Modified?
Here is a more complex example program that will customize various aspect of a graph: