STATISTICA






StatSoft Home Page

STATISTICA VISUAL BASIC (SVB)

General Introduction

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.

Performance of STATISTICA Visual Basic programs. While the obvious advantage of Visual Basic (compared to other languages) is its ease of use and familiarity to a very large number of computer users, the possible drawback of VB programs is that they do not perform as fast as applications developed in lower-level programming languages (such as C). However, that potential problem will not apply to STATISTICA Visual Basic applications, especially those that rely mostly on executing calls to STATISTICA analytic, graphics, and data management procedures. These procedures fully employ the STATISTICA technology and they will perform at a speed comparable to running the respective procedures in STATISTICA directly.

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.

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.

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.

Recording Macros

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:

All three follow the identical syntax and can be modified at a later time, but because of the different ways in which each of them is created, they offer distinctive advantages and disadvantages for specific applications.

1. Analysis Macros. First, you can record simple Analysis Macros from an analysis to record the settings, selections, and chosen options for that specific analysis. [Note that 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).] After selecting any of the statistical options from the Statistics menu or graphics options from the Graphs menu, all actions such as variable selections, option settings, etc. are recorded "behind the scenes"; at any time you can then transfer this recording (i.e., the Visual Basic code for that macro) to the Visual Basic program editor window. Note that the Create Macro command is available from every analysis via the Options menu or the shortcut menu (accessed by right-clicking the analysis button) when the respective analysis is minimized.

Also, your choice of datafiles, as well as case selection conditions and the weight variable, are recorded as long as those options are selected in the analysis dialog (i.e., via the Open Data button and not from the File menu or the status bar). One such "stand alone" macro is created for each analysis and these macros are not "put together" automatically by STATISTICA (in fact they cannot be "mechanically" combined without some editing since each of them represents a stand-alone program that starts with the appropriate declarations, etc.).

2. Master Macros (Logs). Second, you can record a Master Macro or Master Log of your entire analysis; this recording will "connect" analyses performed with various analysis options from the Statistics or Graphs menu. However, unlike simple Analysis Macros, you can turn the recording of Master Macros on or off. The Master Macro recording will begin when you turn on the recording, and it will end when you stop the recording. In between these actions, all file selections and most data management operations are recorded, as are the analyses and selections for the analyses, in the sequence in which they were chosen.

The most common application of the Master Macro would be to start STATISTICA, start the Master Macro recording by selecting Start Recording Log of Analyses (Master Macro) from the Tools - Macro menu, and then continue with the analyses. For example, you can compute descriptive statistics, perform some multiple regression analyses, make several histograms and scatterplots, etc. Note that during the analysis, you will see the floating Record toolbar to remind you that you are currently recording a Master Macro.

Finally, you stop the recording by either clicking the stop button on the floating Record toolbar (see above) or by selecting Stop Recording from the Tools - Macro menu. At that point, the Visual Basic program that represents all actions performed or selections made during the Master Macro recording will be transferred into a STATISTICA Visual Basic editor window. When you run this macro "as is," the exact same analyses will be repeated (with some exceptions resulting from the logic of creating reusable programs from sequences of interactive operations performed by the user, described below).

3. Keyboard Macros. When you select Start Recording Keyboard Macro from the Tools - Macro menu, STATISTICA will record the actual keystrokes you are entering via the keyboard. The floating Record toolbar will be visible as a reminder that a recording "session" is in progress.

When you stop the recording by either clicking the stop button on the floating Record toolbar (see above) or by selecting Stop Recording from the Tools - Macro menu, a STATISTICA Visual Basic editor window will open with typically a very simple program containing a single SendKeys command with symbols that represent all the different keystrokes you performed during the recording session.

Note that this type of macro is very simple in the sense that it will not record any context in which the recorded keystrokes are pressed and will not record their meaning (i.e., commands that these keystrokes will trigger), but this feature makes them particularly useful for some specific applications. For example, it can be very useful when it is attached to a keyboard shortcut (select Customize from the Tools menu to display the Customize dialog; then select the Keyboard tab, where you can attach the program to a shortcut key) where it could be used, for example, to quickly reenter long text, a formula, a selection of variables, or a large number of options (via keystrokes) on some complex dialog.

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:

The input datafiles selection was explicitly recorded, and the Multiple Regression was initialized using the datafile that was explicitly opened for this analysis. Hence, if you run this Master Macro, the analysis will be performed on the same datafile, i.e., it will be loaded from the disk prior to the Multiple Regression analysis.

Now suppose you started the recording of the Master Macro after you had already selected and opened an input datafile. The same analysis might be recorded like this. Now the recording started by defining as the input datafile the currently active input spreadsheet. If you run this Master Macro, the Multiple Regression analysis would be performed on the currently active input datafile, i.e., possibly a different datafile than that used while recording the Master Macro.

Data editing operations. Certain data editing operations on an input spreadsheet (datafile) are recorded as part of Master Macros. As a general rule, most editing operations that are accomplished via selections on respective dialogs (e.g., the Sort Options dialog) are recorded; operations that are performed via simple keyboard actions (e.g., deleting a data value by pressing the Del key on your keyboard) are usually not recorded. Also keep in mind that the Master Macro recording only starts when the recording is explicitly requested; so any editing operations that are performed prior to the start of the recording of course will not be reflected in the Master Macro. Here is a list of data editing operations that are recorded into Master Macros. Most operations available on the Data menu are recorded:

  • Sorting
  • Creating subsets of cases or variables
  • Changes in the variable specifications
  • Data transformations via formulas entered into the specifications dialogs of the respective variables
  • Adding, moving, copying, and deleting variables
  • Adding, moving, copying, and deleting cases
  • Ranking of data
  • Recoding operations
  • Automatic replacement of missing data operations
  • Shifting of data
  • Standardizing data
  • Date operations

    Recordable operations performed outside the Data menu, include:

  • Creation of new datafiles (spreadsheets)
  • Opening datafiles
  • All Output Manager options
  • Filling data ranges with random values (note that this operation is recorded even though it is accomplished without going through dialogs, but by selecting it from the Edit menu)
  • Entering case selection conditions on a global and local (one analysis) level
  • Entering case weight variables on a global and local (one analysis) level

    Note that recording of certain operations as part of the Master Macro logs might lead to creating ambiguous and context-dependent solutions, so they are excluded from the list of recordable tasks. This includes such operations as:

  • Editing values in the spreadsheets
  • Selections of cells
  • Clipboard based copy, paste, and delete operations (note that this does not include the copy, move, and delete cases and variables operations listed above)
  • Generally, anything not on the list of recordable data management operations (see above).

    Keep these issues in mind when recording a Master Macro with data editing operations that are necessary before subsequent analyses are performed.

    Recording consecutive and simultaneous analyses. To reiterate, Master Macro recordings will reproduce the exact sequence of analyses and output choices (of results spreadsheets or graphs) made during the analysis. This facility provides great flexibility and even allows you to "string together" analyses so that the first one computes certain results, while the second one analyzes those results further. For example, you could first perform a Multiple Regression analysis on a particular datafile, then use the option Save on the results dialog of the Multiple Regression analysis to create a stand-alone input spreadsheet of predicted and residual values from the analysis, and then compute Basic Statistics on the numbers in that spreadsheet. The Master Macro recording of that sequence of analyses would look something like this (for program details see also the STATISTICA Visual Basic Primer): Note how consecutive analyses (objects) are enumerated as newanalysis1 and newanalysis2. The first one (Multiple Regression) is initialized with an explicit input datafile; the second one is initialized with the currently active dataset. When recording complex sequences of analyses like these where results of one analysis serve as the input for subsequent analyses, extra care must be taken to review and, if necessary, edit the final macro before running it to ensure that the intended sequence of ActiveDataSets are chosen by the respective analyses.

    Case selection conditions, case weights. Like Analysis Macros, when case selection conditions or case weights are specified during an analysis, those actions are properly recorded in the Master Macro. However, in addition, when you specify case selection conditions and case weights globally for the datafile (i.e., outside any specific analysis), those actions are recorded as well.

    Handling output: Sending results to workbooks, reports, etc. Like Analysis Macros, when case output options are changed during an analysis, those selections are recorded in the macro. In addition, if global output defaults are changed via the Tools - Options menu (on the Output Manager tab of the Options dialog), then those choices are recorded into the Master Macro as well. Therefore, if you started a Master Macro, then set the global Output Manager option to direct all results spreadsheets and graphs to separate workbooks (for each analysis) as well as to reports, then those selections will be recorded in the Master Macro and reproduced when you execute that macro.

    Master Macro recording and Analysis Macro recording. The two major modes of macro recording - Master Macros and Analysis Macros, which are always being recorded in the "background" -- can be used simultaneously. In other words, you can make Analysis Macros while recording a Master Macro. However, note that the action of creating the Analysis Macro is not itself recorded in the Master Macro.

    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.

    Components of Recorded Macros

    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:

    Here the new analysis object is created of type Analysis with the constant scBasicStatistics, and with the current ActiveDataSet as the input data file; this statement will display the Descriptive Statistics (Startup Panel). Note that scBasicStatistics is actually a predefined (in SVB) numeric constant. If you have recorded a Master Macro, the SVB syntax would look slightly different; specifically, the input datafile would be explicitly assigned to a variable of type Spreadsheet (e.g., Set S1 = ActiveSpreadsheet), and consecutive analyses would be numbered, and initialized using that variable (e.g., Set newanalysis1 = Analysis (scBasicStatistics,S1)).

    Next, there is the block: The With newanalysis.Dialog block is a shortcut method for setting the various properties available on the startup dialog; in this case the only property is the Statistics property, which selects the Descriptive statistics option on the startup dialog. The newanalysis.Run statement "clicks" OK, i.e., causes the program to proceed to the next dialog. The next dialog block sets the many properties of the Descriptive Statistics dialog. Finally, at the end of the macro you have:
    These two lines select the Summary results spreadsheet and the Histograms button on the Normality tab (in a sense these commands "click" those buttons). The RouteOutput method takes as an argument the Summary or Histograms 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 dialog. The RouteOutput method actually returns an object of type AnalysisOutput, which itself has a number of methods and properties to make it fully "programmable."

    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.

    General SVB Language Features

    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:

    The Variant data type. A data type that is particularly useful when incorporating STATISTICA statistical procedures into your SVB program is the Variant data type. A variable declared as a Variant data type can be empty, numeric, currency, date, string, object (see What Is Meant By the Term "Object Model?", page 939), error code, null or array value. Here is an example program that demonstrates the Variant data type. Note that all variables that are used in a program but are not explicitly declared, will automatically default to type Variant.

    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:

    Assigning objects to variables. When assigning objects to variables, you need to use the syntax Set Variable = Object; for example:

    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.

    To run this program, press F5 or select Run Macro from the Run menu.

    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.

    Here is the functionally identical program, where the variable is declared globally.

    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

    The Object Module: KeyCodesObject The main program: RetrieveKeyCodes Before you run this program, make sure that the respective class and object module files exist in the correct locations; note that you could also save all files in the default directory for global macros (e.g., in the root directory of the STATISTICA installation on your machine), and then use the asterisk convention to reference the files, e.g., via #Uses "*KeyCodesClass.svc". Two different "key-codes" will be retrieved. Suppose that a very elaborate (and perhaps confidential) method exists to generate the key codes. By using object (or class) modules, you could encapsulate inside the object (or class) the method for creating the keys; this method could then be modified, updated, etc., while the main program that retrieves those keys by accessing the object (class) would not have to change.

    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:

    This assumes that these routines are located in DLLTest.dll, and that this DLL is located in the J:\DLLTest\Debug\ directory. Note that if the DLL was located in the system search path (like the SYSTEM32 directory), then only the DLL name is needed.

    The Alias statement is used to define the exact name the compiler defines for this function. The __stdcall calling conventions dictate that the function name is preceded by an underscore ("_"), and appended by an @ and followed by the size in bytes of all the parameters. Since the example function is passing a 4-byte integer, then the name will have "@4" appended. Note that you can omit the Alias clause if you make an entry in the .DEF file for the custom DLL. If you add an entry for SampleFunction and SampleSubroutine, then the linker will create an alias without the underscore and the @XXX suffix.

    SVB Development Environment

    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.

    Visual Basic maintains and updates an object called Err. The property Err.Description contains the description of the most recent error. To clear the last error event, set Err to zero. It is generally good programming practice to write the subroutines and functions so that "clean" error exits can be accomplished, i.e., that code is provided that explicitly handles any errors.

    STATISTICA analysis errors. Fatal errors (those that prevent the respective analysis from being completed) that occur as part of the analysis inside a STATISTICA module (e.g., incorrect selection of variables) are handled in the same way as during the interactive analysis, i.e., the program will display a message box explaining the error that has occurred, and how to remedy it.

    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:

    You can retrieve all information regarding non-fatal errors (warnings) that occur during a STATISTICA analysis into a Spreadsheet object; you can then apply all the standard Spreadsheet methods and properties to retrieve the desired information for display in the MS Excel spreadsheet.

    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.

    Using SVB to Manage Analyses, Data Files, Graphs, etc.

    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:

    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 dialog. 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 that the actual selections on the Analysis/Graph Output Manager dialog are typically 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 (accessed from the Tools - Options menu).

    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, which allow you to organize and manage all other documents. There are a large number of properties and methods available for each of these types of documents, that allow you to customize your results, or to access aspects of your results for further processing.

    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

    *The ANOVA results dialog functions are accessible via the General Linear Models library.

    †The Distribution Fitting module functions and routines are part of the Nonparametrics library.

    ‡The Principal Components and Classification Analysis techniques are accessible via the Factor Analysis library.

    Note 1: The list of modules and procedures and STATISTICA libraries available to Visual Basic is constantly growing. Please check the StatSoft, Inc. Web site frequently (www.statsoft.com).

    Note 2: The Graph menu graphs are all part of the STATISTICA main reference library; you can review the respective constants to instantiate a particular analysis (graph type) in the Object Browser.

    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:

    However, in recorded macro programs, you will also see the so-called RouteOutput method, which will send the respective collection of output objects (graphs, spreadsheets) to stand-alone windows, workbooks, and/or report, depending on your current Analysis/Graph Output Manager settings. The next section briefly describes the RouteOutput method and AnalysisOutput objects.

    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.

    Note that this program does not create an Analysis object via Set newanalysis =...; instead it creates a blank graph "from scratch" and then sets data directly into the graph. The graph will look like this:

    You can further customize all aspects of this graph from within the SVB program; review the different properties and methods that apply to the various graphics objects in the Object Browser.

    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:

    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 dialog. 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 that the actual selections on the Analysis/Graph Output Manager dialog 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 Tools - Options dialog.

    Suppose in your interactive analysis all results spreadsheets were automatically placed into a workbook; a macro recorded from such an analysis might look as shown in the following example. This example also illustrates how to access the results documents in the AnalysisOutput object (i.e., edit the recorded macro to access the results spreadsheets).

    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.

    After running this program, a workbook will be created that looks something like this (depending on other default systems currently active in your system).

    Note that further customizations, such as changing of titles, adding text, etc. can easily be achieved by further modifying various properties of the output objects, or the workbook.

    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:

    As you can see, to set the font of the x-axis labels to bold, you retrieve the Graph object, then the ("polymorphic," i.e. depending on the graph) Graph Content object, then the Axis2D object, then the GraphicsFont2 object, then the FontFace object, and finally set the Bold property. This example illustrates how learning STATISTICA Visual Basic means learning to navigate the STATISTICA object model. Fortunately, the object model is organized into a logical hierarchy, and it can be reviewed via the Object Browser.

    How Can Other Aspects of Graphs Be Modified?

    Here is a more complex example program that will customize various aspect of a graph:

    This program will create a 2D line plot and customize various aspects of this plot.

    In general, in order to modify, copy, delete, etc. any aspect of a graph, locate the respective property in the object model.

    Can I Use SVB to Develop "Extensions" of STATISTICA and My Own New "Modules?"

    This is one of the many useful applications for STATISTICA Visual Basic programs. By recording routine analyses, you can quickly generate all the necessary program code to perform particular analyses. By combining the code from different programs, and by customizing perhaps some of the user interface, a completely new module can be created that will perform custom analyses. Shown below is an example program that will combine multiple analyses.

    As you can see, the SVB environment not only allows you to automate routine analyses, but also in a sense to "program your own statistical package" with various nonstandard options tailored to your specific needs.

    How Can I Attach a Macro Program to a Toolbar Button (Keyboard Command, or Menu Option)?

    One common application of STATISTICA Visual Basic macro programs is to "enhance" the STATISTICA functionality by creating toolbar buttons or keyboard commands (e.g., CTRL+key sequences) that allow you to quickly perform a series of operations or routine analyses. Shown below is a simple program that will sort a spreadsheet in a workbook, by the (first) selected column.

    First, create this macro by selecting File New, and then on the Macro tab call this new macro program SortColumn; then click the OK button. Next type (or paste) in this program, and save it (e.g., as SortColumn.svb).

    Select Customize from the Tools menu, and select Macros in the Categories list.

    Now drag the SortColumn macro in the Command list onto the toolbar. A new toolbar button will be created, identified by the name of the macro.

    In the illustration above, a "smiley face" was added to the SortColumn button. To do this, select Tools - Customize; then, while the Customize dialog remains displayed, right-click on the SortColumn button and select Button Appearance.



    The Button Appearance dialog is displayed, where you can select a predefined icon or make a new one for the new button.

    Attaching the macro to a shortcut key. To "connect" this macro program to a shortcut key, launch the Customize dialog again (View - Toolbars - Customize), and select the Keyboard tab. Select Macros in the Category box, and select Macro in the Set shortcut key for box. In the Commands list select SortColumn, and then choose CTRL+ALT+S as the key sequence for executing the SortColumn macro program. To do this, click in the Press new shortcut key box, and then press CTRL+ALT+S; this key sequence will now be displayed in this box, and the Assign button will become available. Click the Assign button to finalize your choice.

    After you Close this dialog, the SortColumn macro program can now be executed from the keyboard by pressing CTR+ALT+S.

    Attaching the macro to a menu. To attach the macro program to a menu item, select the Commands/Macros tab on the Customize dialog. Select Macros in the Categories box, and the SortColumn macro will be displayed in the Commands box.

    Click on the SortColumn macro, and drag it to the desired menu and menu location (e.g., the end of the Edit menu).

    As you can see, the new macro was appended now as a menu item at the end of the Edit menu.

    Running SVB Programs from Other Applications

    Can I Execute an SVB Program from within Other Visual Basic Compatible Applications?

    Yes; in general, because of the industry standard compatibility of STATISTICA Visual Basic, you can execute STATISTICA Visual Basic programs from any other Visual Basic compatible environment (e.g., Microsoft Excel, Microsoft Word, or a stand alone Visual Basic language; in practice, you would typically call STATISTICA functions from VB in another application). However, there are a few considerations and limitations that you need to be aware of:

    STATISTICA libraries must be properly licensed and installed. When you run a STATISTICA Visual Basic program or attempt to call STATISTICA functions from any other application, all calls to the STATISTICA specific functions (as opposed to the generic functions of Microsoft Visual Basic) will be executed only if the respective STATISTICA libraries are present on the computer where the execution takes place - that is, the user of the program must be a licensed user of the respective STATISTICA libraries of procedures. Note that this large library of STATISTICA functions (more than 10,000 procedures) is transparently accessible not only to Visual Basic (either the one that is built in, or a different one), but also to calls from any other compatible programming language or environment, such as C/C++, Java, or Delphi.

    The proper STATISTICA libraries must be loaded. In order to access the thousands of library functions available in STATISTICA, the respective object reference libraries must be loaded. For example, in Microsoft Excel, use option Tools - References and then select the STATISTICA Object library, and any other libraries that you would want to access.

    The STATISTICA Application object must be explicitly created. When you run STATISTICA Visual Basic programs from with the STATISTICA program editor, then a few shortcuts are available. In particular, the STATISTICA program editor assumes that the current application is STATISTICA, so it doesn't have to be initialized. However, when running STATISTICA from within another application (e.g., from within the Microsoft Excel Visual Basic editor), you have to explicitly declare the STATISTICA Application object.

    Some other limitations and differences between SVB and Visual Basic in other applications. While the objects of the STATISTICA libraries are fully exposed and accessible to all compatible Visual Basic programming environments in other applications, there are a few functions that are only available in SVB, i.e., when the Visual Basic program is run from within STATISTICA. (Likewise, there are some functions in other applications that are not accessible in the SVB environment.) Specifically, all user interface functions, such as user-defined dialogs or functions for retrieving variable lists or value lists (via dialogs from the user) are closely tied to the STATISTICA application itself. 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.

    How Can I Run a STATISTICA Analysis from Microsoft Excel?

    First, if you want to run STATISTICA from within the Visual Basic environment in Microsoft Excel, be aware of the issues (and some limitations).

    To illustrate, we will create an example program that can be run from Visual Basic within Excel. After starting Excel, create a new Worksheet. Then select Macro - Visual Basic Editor from the Tools menu. From the Visual Basic Tools menu, select References.

    The References dialog allows you to select the libraries (objects) that you would like to be visible inside the Visual Basic program. To make STATISTICA visible, select the STATISTICA Object Library, and the STATISTICA Basic Statistics Library (for the current version of STATISTICA); then click the OK button.



    Now type or paste the following program into the program editor.

    When you run this Visual Basic program from inside Microsoft Excel (Visual Basic Editor), it will paste the results from the Summary results spreadsheet of the Basic Statistics - Descriptive Statistics analysis into the current Excel Spreadsheet. Note that this is accomplished without the user ever seeing or having to interact with the STATISTICA application; the program runs entirely invisibly, and the results are displayed inside the Excel spreadsheet. This simple example illustrates the power and versatility of the STATISTICA Visual Basic object model: All analysis and graphics options and methods available in STATISTICA are fully exposed in the respective object libraries, and even advanced and complex analyses can be automated and performed routinely "behind the scenes" from within any other Visual Basic compatible application.

    Handling Large Computational Problems, Matrices

    What Is the Capacity of SVB, and Can It Handle Large Computational Problems?

    STATISTICA Visual Basic is a powerful programming language which combines the general Visual Basic Programming Environment [with facilities and extensions for designing user interfaces (dialogs) and file handling], with the STATISTICA libraries with thousands of functions that provide access to practically all functionality of STATISTICA. It is well suited to handle large computational problems.

    SVB supports local data arrays with up to 8 dimensions, and there is no limit to the size of the arrays (all memory available in your system can be used, including virtual memory, e.g., correlation matrices 1,000 x 1,000 and larger can be computed [with a single function call] on most systems), so custom procedures involving operations on large multidimensional matrices can be developed (a comprehensive selection of matrix operations are also supported). Matrices can be dynamically allocated or redimensioned in run time.

    Performance of STATISTICA Visual Basic programs. While the obvious advantage of Visual Basic (compared to other languages) is its ease of use and being familiar to a very large number of computer users, the possible drawback of VB programs is that they do not perform as fast as applications developed in lower-level programming languages (such as C). However, that potential problem will not apply to STATISTICA Visual Basic applications, especially those that rely mostly on executing calls to STATISTICA analytic, graphics, and data management procedures. These procedures fully employ the STATISTICA technology and they will perform at a speed comparable to running the respective procedures in STATISTICA directly.

    Does SVB Support Matrix Operations?

    STATISTICA Visual Basic contains a large number of designated matrix and statistical functions, which make the SVB environment ideal for prototyping algorithms or for developing custom statistical procedures. The matrix and statistical functions are documented in detail in the section on the STATISTICA Matrix Function Library (see the Electronic Manual).

    One major advantage of using the STATISTICA library of matrix functions, instead of writing these functions "by hand" in Visual Basic, is that the former will evaluate much faster. For example, when you want to invert large matrices, the MatrixInverse function will perform the actual matrix inversion using the highly optimized (compiled) algorithms of STATISTICA.

    Include file: STB.svx. To provide convenient access to the matrix functions without requiring you to pass explicitly the dimensions of the arrays that are being passed, STATISTICA includes a file with function interfaces: STB.svx. You may want to open this file to review the functions and see how they provide simplified access to the actual matrix library. It is recommended that you routinely include that file at the beginning of your program when you intend to use functions from the STATISTICA libraries of matrix and statistical functions.

    In order to insure the portability of all STATISTICA Visual Basic macros, you can specify an asterisk in front of the root file name for the standard include files. When STATISTICA detects the *, it will automatically search for the STB.svx file in standard places (e.g., the directory where the macro has been saved, the global macro directory, and the directory where the STATISTICA application is located). Thus it is not necessary to state the complete path for the STB.svx file when including this file in your STATISTICA Visual Basic programs via the $Include statement.

    Reviewing the matrix functions in the function browser. You can review the available matrix functions either in the Electronic Manual or in the Function Browser, which also lists various other functions available in STATISTICA Visual Basic. The Function Browser is accessible via the SVB View menu or by clicking on the Function Browser toolbar button.

    Example. The following example illustrates how to use the functions in the STATISTICA library of matrix functions, to perform some basic matrix operations: Namely, matrix inversion and matrix multiplication:

    How Can I Use the Data in a Spreadsheet with Matrix Functions? (How Do I Copy Data Efficiently from Spreadsheets to Matrices, and Back?)

    STATISTICA Visual Basic contains several functions to quickly move columns (variables), rows (cases), or the entire data matrix from spreadsheets to dimensioned arrays, and back. The following example shows how you can use the .VData(variable), CData(case), and .Data properties of the spreadsheet object to retrieve particular columns (variables) or rows (cases) of data from the respective spreadsheet, or to copy the entire data matrix.

    Note that internally, the .VData(variable), CData(case), and .Data properties perform copying operations either from or to a dimensioned array. You can only use these properties as arguments in matrix function calls if those functions do not write values back to the respective input matrix (so you could not, for example, use them directly in the call to the MatrixElemAdd function as shown above). Also, the dimensions of the arrays used in conjunction with these properties must match the respective dimensions (row, column, or both) of the spreadsheet.

    Changing individual values in a spreadsheet. When using the Vdata, CData, and Data properties it is also important to remember that they will actually "move" data; for example, the Data property will move the data from the respective spreadsheet to the specified array. Therefore, when performing operations in a loop, for example in order to update particular cells in the spreadsheet only, it is much more efficient to use the Value(case,variable) property.

    Creating and Managing Custom Dialogs in STATISTICA Visual Basic

    Can I Create Custom Dialogs and Other Interactive User Input Controls in SVB?

    The STATISTICA Visual Basic environment provides all tools to program complete custom user interfaces. A powerful User-Dialog Editor is included to design dialogs using simple operations like dragging buttons to the desired locations. Unlike in Microsoft Visual Basic, the user-defined dialogs will be stored along with the program code as data of type UserDialog. This method of creating dialogs allows you to create sophisticated user interfaces that can easily be edited in textual form; also, by defining the entire dialog as a variable, you can completely define dialogs inside subroutines, which can be freely moved around the program.

    However, user-defined dialogs designed in the STATISTICA Visual Basic environment cannot be ported directly to Microsoft Visual Basic, which uses a form-based method of creating dialogs. This is not a serious limitation, though, but rather a design issue, in the sense that you should decide before embarking on the development of a complex program with extensive custom (user-defined) dialogs which environment you would prefer. For example, if you are already familiar with the Microsoft Visual Basic environment, or would like to augment an existing program that was developed in that environment, then there would be clear advantages in staying with that language. To reiterate, virtually all STATISTICA Visual Basic functions are accessible from the Visual Basic environments in other applications (such as Microsoft Visual Basic, Microsoft Excel, Microsoft Word, etc.).

    The following example illustrates how to create a simple dialog and "service" the user choices on this dialog. Start by creating a new macro: Select New from the File menu, select the Macro tab, and create a new macro called SimpleDialog.

    Creating the dialog. Next select Dialog Editor from the Tools menu or click the Dialog Editor toolbar button to display the UserDialog Editor.



    Click the OK button on the left side of this dialog, and then click in the upper-right corner of the window; an OK button will be inserted in that location.



    Note that you can further edit the size and location of the OK button by clicking on it and dragging it to the desired location, or resizing it. Repeat these steps for the Cancel button and for a user-defined button. The latter can be produced by clicking the blank button toolbar button on the lower-left of the toolbar on the UserDialog, and then clicking on the desired location in the dialog editor.



    By default, the new button is labeled Pushbutton1; to change that, double-click on it to display the Edit PushButton Properties dialog. Then edit the fields as follows:



    Note that the Caption for the new button is &My Button! When you click Close, the actual caption of the button will change to My Button!, i.e., with the M underlined. Thus, M is the keyboard accelerator that will "click" this button. The other important information in the Edit PushButton Properties dialog is the ID of the button, entered into the Field box. The ID for this button is MyButton; this ID will be referenced throughout the SVB program to service the button, i.e., to identify when the button was pushed, and to respond inside the program.

    Now close the Edit PushButton Properties dialog, and close the UserDialog Editor dialog by clicking on the toolbar button in the UserDialog editor. The SVB program will now contain the following code.

    Remember that to learn more about the different keywords and statements used in this program so far, you can always select the respective text, and then press F1 to display the Electronic Manual, which explains the syntax for the respective keyword or statement and provides simple examples on how to use them.

    Servicing the new dialog, simple dialogs. If you run the program created thus far, the dialog we designed will be displayed on the screen; when you click on any button the program will terminate. The next task is to "connect" specific programming instructions to different user actions on the dialog. For example, you could display message boxes to indicate which button the user clicked.

    The simplest way to do this is to use the codes returned by the Dialog method; this method will return a 0 when Cancel is clicked, -1 for OK, and different integers greater than 0 to enumerate the other controls on the dialog. So in this example, clicking the My Button button would return a 1. Here is the program that would service all buttons. This program uses the standard Visual Basic Select Case statement to execute the code for the desired message box, based on the ID number returned by the Dialog method; you could of course also accomplish the same effect by using If ... Then ... Else statements. (All general Visual Basic statements are documented in the general SVB syntax help.)

    How Are the Different Controls in Custom Dialogs "Serviced?"

    Here is a fairly elaborate example program to illustrate how to service the various elements commonly used in dialogs.

    This example program is fairly complex and illustrates how to interact with the different standard Windows dialog controls. Remember that the Electronic Manual contains detailed documentation for the statements, declarations, and data types used in this program.

    Defining dialogs in subroutines; defining sequences of dialogs. In this example program, the dialog is defined in and displayed by a subroutine (function), rather than the main program. Thus, by defining different dialogs in different subroutines, you can build elaborate programs with complex flow control, i.e., sequences of dialogs that depend on prior user choices or results of computations.

    Zero referencing in ListBox, DropListBox, and OptionGroup controls. Remember that the elements in ListBox, DropListBox, and OptionGroup controls are zero referenced, i.e., the first element is referenced as number 0 (zero), the second as number 1, etc. Note that this is the default way in which arrays are referenced unless Option Base 1 is set; if you have problems running this program, make sure that Option Base 1 is not set at the beginning of your program.

    Retrieving numeric values. The program also illustrates how standard text controls can be used to return numeric values (see the .MyTextBox2 control). Specifically, the program retrieves the user entered value as text, and later checks whether the text can be converted into a valid value of type Double; this is accomplished by defining an On Error Goto label in the RetrieveUserDialogFields function, where the program control will resume when an error occurs in the CDbl conversion function.

    Changing controls from inside the dialog function. When you run the program and click the Reset to defaults button (with the dialog ID "MyButton"), all fields will be reset to their defaults. This is done via the DlgText and DlgValue functions, as is illustrated in case "MyButton" in the dialog function.

    Customizing the Appearance and "Behavior" of STATISTICA

    What Are Application Events and How Can They Be Controlled from SVB?

    An event is an action that is typically performed by a user, such as clicking a mouse button, pressing a key, changing data, or opening a spreadsheet or workbook. In STATISTICA certain events are visible to the outside world, i.e., accessible to STATISTICA Visual Basic, and they can be used to customize its behavior. Using programmable events you can tailor the program's behavior to the users' needs. Examples of events applications might include:

  • building auditing systems into STATISTICA (by IT departments),
  • building interactive demonstration programs based on workbooks,
  • building customized user interfaces adhering to specific requirements of a particular application (or a specific company, e.g., to meet specific security requirements).

    Events are an important part of the set of tools built into STATISTICA to make it a powerful solution building system. There are three basic types of events: those pertaining to STATISTICA documents (e.g., spreadsheets), those pertaining to the STATISTICA application as a whole (e.g., opening a spreadsheet), and those pertaining to specific analyses (e.g., Basic Statistics, or 2D Scatterplots).

    Document-level events. These events occur for open documents and in some cases, for objects within them. For example, the workbook document object can respond to the Open, New, and Print events; the spreadsheet document can respond to events such as changed data values, or double-clicking on a cell.

    Application-level events. These events occur at the level of the application itself, for example, when a new report, graph, or workbook is created. You can create an event handler customizing these actions for all documents.

    Analysis-level events. These events occur at the level of a specific analysis, for example, when you close an analysis using the Basic Statistics methods, or before an analysis (e.g., Basic Statistics) is sending results to a spreadsheet or graph. Note that 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). A typical application using analysis-level events would be to implement custom handling of output, for example, to send all graphs and results spreadsheets to another application.

    A simple example. Here is a very simple example of how a STATISTICA Visual Basic program can be connected to the application-level event of starting a new analysis. Start by selecting View code from the Tools - Macro - Application events menu. A Visual Basic editor will open; in the Object box of that editor, select Document, and then select AnalysisNew in the Proc box. Enter the simple MsgBox instruction as shown below.

    Next select Autorun from the Tools - Macro - Application events menu and close the program editor. Every time that you start a new analysis (e.g., select Basic Statistics from the Statistics menu), the message You are starting a new analysis will be displayed. In fact, you can now exit the program, respond Yes when prompted to save the documents events, and the next time that you start STATISTICA and select an analysis, the message will be displayed. To turn off this program, deselect Autorun from the Tools - Macro - Application events menu.

    How Can I Create a Cell-Function Spreadsheet Using Spreadsheet Events?

    One of the most basic functions of the designated spreadsheet software (such as Microsoft Excel) is to automatically recompute cells in the datafile when any of the input data (cells) are changed. For example, you can set up a complex budget for a project so that when you change the values for particular budget items, the entire budget will be recomputed based on the newly supplied values.

    The same functionality can be programmed into STATISTICA Spreadsheets by attaching an SVB macro to certain spreadsheet events as demonstrated in this example. Note that practically all spreadsheet (and other) events can be customized, thus providing the tools to build very sophisticated and highly customized automated data operations right "into" the spreadsheet.

    How is the macro created? First, create a datafile and set up the necessary cells. Datafile CellFunctionDemo.sta (available in the Examples\Macros directory which can be found in the directory in which you installed STATISTICA) contains prices for various items on a holiday shopping list.



    Note that in the spreadsheet shown, the Item Cost and Coupon variables are data input variables and the Final Item Cost and Total Cost of All Items variables are derived or computed variables.

    Entering the computations for derived cells (programming the DataChanged event). After entering the basic information, using the View menu, select Events - View Code. This displays the SVB program editor for document level events (i.e., events that apply to the newly created spreadsheet document). In the Object box of the SVB editor (Document Events dialog), select Document; in the Proc box, select the DataChanged event. Shown below is the appearance of the SVB editor after the DataChanged subroutine has been created in the editor.



    Now type in the following program into the SVB editor (you can, of course, omit the comments).

    This macro defines the computations for the cells in the spreadsheet that will be performed every time the data in the input variables are changed.

    Write protecting the derived cells. Also, we want to make sure that certain cells are "protected," i.e., users should not be able to type values into the cells that are derived (by computation from other cells). Some of that protection is already implemented in the macro shown above, which checks whether or not the user attempted to type a value into a derived cell. For this example, let us also "catch" the BeforeDoubleClick event for the cells in the third and fourth variables of our example spreadsheet. Select in the Proc field of the SVB editor the BeforeDoubleClick event, and then enter the code as shown below: Saving the spreadsheet and AutoRun. Finally, before saving the macro and the datafile, click on the data spreadsheet once more, and using the View menu select Events - Autorun.

    This will cause the new macro to run automatically every time you open the data spreadsheet. Next, save the spreadsheet and run the macro. You are now ready to compute your holiday shopping budget using your customized spreadsheet. If you try to "cheat" by double-clicking on one of the computed fields to enter a (lower) total value, a message will be displayed.



    This simple example illustrates how you could build very sophisticated "cost models" that can also include dialogs, automatic analyses with the STATISTICA statistical or graphics functions, or any of the more than 10,000 automation functions available in the STATISTICA system, thus vastly expanding the functionality of ordinary spreadsheets.

    Can I Customize the Toolbars and Menus via SVB?

    STATISTICA provides full access to all of its customization options via STATISTICA Visual Basic functions. A detailed discussion of the techniques available for customizing toolbars, menus, etc., and how to use these methods to fully customize or expand STATISTICA is beyond the scope of this introduction. There are many excellent books available that discuss in detail the CommandBars object and how to use it in (Microsoft) Windows applications (e.g., to customize Microsoft Office applications). In general, customizing toolbars, menus, pop-up menus, etc. is useful in order to:

  • Provide quick access to frequently used options or methods;
  • Program highly customized events; e.g., to customize the shortcut menu when the user clicks on certain objects by adding macro programs or links to other applications to that menu;
  • Program fully customized versions of STATISTICA dedicated to perform only few predefined tasks (e.g., a version for data entry only);
  • Add new options to STATISTICA developed by other vendors; those options could be invoked from a STATISTICA Visual Basic macro program, if they are accessible as reference libraries.

    Example. The following example illustrates how to produce a custom toolbar, and how to attach to them particular events. After running this program, a new toolbar will be added to your installation of STATISTICA. To remove the new toolbar, select Customize from the Tools menu, and then select the Toolbars tab; select the new toolbar, and Delete it. (You could also write an SVB program to remove the new toolbar, using the CommandBar.Delete method.)
    Back to Top
    Request Quote
    StatSoft Home Page



    If your question is not answered above, please e-mail us, or call (918) 749-1119 Monday through Friday, 9:00AM to 5:00PM Central Time. Please include your serial number (select About STATISTICA from the Help menu to view your serial number) and information about your hardware (the type of processor (CPU), the amount of memory (RAM), and disk space) and the version of the operating system that you are using. If you live outside North America, please contact your local StatSoft office. (Please note: Technical Support is only for users of the latest version of the program.)


    [StatSoft]
    2300 East 14th Street, Tulsa, OK 74104
    Phone: (918) 749-1119; Fax: (918) 749-2217

    [StatSoft]e-mail: info@statsoft.com

    ©Copyright StatSoft, Inc., 1984-2004.
    StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.