Analysis-Level Events Example

AAAnalysis-level events can be used to customize behavior of all Statistica analyses. To create a macro that customizes the behavior of all output in an analysis macro, follow these steps:

Open the data file Adstudy.sta, select Basic Statistics and Tables from the Statistics menu, and run a descriptive statistics analysis. Once you are finished with your analysis, select Create Macro from the Options button in the analysis dialog box to display the recorded macro.

Near the top of the macro, you will find this line:

Dim newanalysis As Analysis

Remove this line of code and then enter the following at the top of the macro (at the global level):

Dim WithEvents newanalysis As Analysis

The WithEvents keywords will enable you to handle the analysis' events. Next, write a handler by using the function prototype of the event and place the name of the object and an underscore in front of the function name. For example, for the BeforeOutput event associated with the object newanalysis you would write:

Sub newanalysis_BeforeOutput(ByVal Output As Object, _ Response As AnalysisOutputResponse)

End Sub

Within this function we will intercept the output of the analysis before it is routed to the default output mechanism in Statistica. In the following example, the output will be saved to your C: drive and then the display of the output in Statistica will be ignored:

Sub newanalysis_BeforeOutput(ByVal Output As Object, _ Response As AnalysisOutputResponse)

'remove any illegal characters from the name of the output Dim Name As String Name = Output.Name Name = Replace(Name,":","") Name = "C:\" & Name 'save the output Output.SaveAs(Name) 'do not display the output, just save it Response = scCancel

End Sub

See also Macro Event Behavior.