Macro (SVB) Programs Example - Statistica Dialog Boxes for Selecting Variables

When modifying a recorded macro to create a custom program, you often need to allow the user to select variables for the analysis. SVB contains a number of functions to accomplish this (note that these functions are not available to the implementations of Visual Basic in other programs; see also Objects, Methods, and Properties, or Custom Dialogs; Custom User Interfaces for details). Shown below is a simple example program for retrieving one, two, and three lists of variables. Before running this program, be sure that an input data spreadsheet is currently open and marked for input.

Sub Main
' Declare the arrays of Integer's or Long's,

' to hold the variable lists; note that they

' are declared here without an explicit

' dimension yet.

Dim VarList1 () As Long
Dim
VarList2 () As Long
Dim
VarList3 () As Long
Dim
Nvars As Long

' The InList1, 2, and 3 will hold the number
' of variables that were selected.

Dim InList1 As Long
Dim
InList2 As Long
Dim
InList3 As Long
Dim
ret As Integer

' This statement retrieves the number of variables
' in the current "active for input" data Spreadsheet.

Nvars = ActiveDataSet.NumberOfVariables
If
Nvars<1 Then GoTo Finish

' Next the array of Long values VarList1, 2, and 3
' are re-dimensioned; we will allow up to the total

' number of variables in the input Spreadsheet to

' be selected into the VarLists.

ReDim VarList1(1 To Nvars)
ReDim
VarList2(1 To Nvars)
ReDim
VarList3(1 To Nvars)

' Note that the SelectVariables functions return 1 if
' the user exited by pressing OK; they return 0 if the

' user exited by pressing Cancel.

'

' The syntax for this call is as follows:

'ret = SelectVariables1 ( _

'ActiveDataSet, _ ' Input Spreadsheet Data
'"Variables for Analysis", _ ' Window title

'1, Nvars, _ ' minimum and maximum number of variables allowed

'VarList1, _ ' List of variables; prior selection on input;

' ' actual selection of variables on output

'InList1, _ ' Number of variables selected in InList1

'"List 1") ' Prompt (title) for list 1

ret = SelectVariables1 ( _
ActiveDataSet
, _
"Variables for Analysis", _
1, Nvars, _
VarList1, _
InList1, _
"List 1")

If ret=0 Then GoTo Finish

' Note that the variables selected into VarList1 in
' function SelectVariables1 will automatically be

' selected by default in VarList1, of SelectVariables2.

ret = SelectVariables2 (ActiveDataSet, _
"Variables for Analysis", _
1, Nvars, VarList1, InList1, "List 1", _
1, Nvars, VarList2, InList2, "List 2")

If ret=0 Then GoTo Finish
ret = SelectVariables3 (ActiveDataSet, _
"Variables for Analysis", _
1, Nvars, VarList1, InList1, "List 1", _
1, Nvars, VarList2, InList2, "List 2", _
1, Nvars, VarList3, InList3, "List 3")

Finish:
End Sub

When you run this program you will notice that the variable selections will "persist" into the subsequent calls of the SelectVariables function, so variables selected into the first list in the first call will be the default selection for the first list in the second call, and so on.