Using Arrays of Values to Set the .Variables Property

The manner in which variable selections are recorded in macro (SVB) programs is discussed in Recording Macro (SVB) Programs Example - STATISTICA Dialog Boxes for Selecting Variables. When modifying a previously recorded macro, or when you want to include previously recorded code into a more complex custom program, you often need to assign user-specified lists of variables to the .Variables property, or assign variable lists that were computed or derived in some other part of the program

By default the recorded macro will reflect the variable selection (for the interactive analysis, from which the macro was recorded) as a string with variable numbers; for example:

.Variables = "5 6 7 8"

The .Variables property also accepts variables of type Variant, or arrays of type Integer or Long. So for example, instead of the string "5 6 7 8", you could set the variables as:

Dim VariableList (1 To 4 ) As Integer
 Dim i As Integer
 For i=1 To 4

VariableList (i)=i+4

Next i
 With newanalysis.Dialog

.Variables = VariableList

End With

When the analysis requires two lists of variables (e.g., in Multiple Regression, to select a dependent and independent variable list), you can use the Visual Basic Array function, to create a single Variant array from two integer arrays, that can be used to set the .Variables property. For example, the specification that could be recorded from the Multiple Regression module as:

.Variables = "5 6 7 | 1 2 3 4"

could also be written in this manner:
  

Dim DepVarList (1 To 3) As Integer
 Dim IndepVarList(1 To 4) As Integer
 Dim i As Integer
 For i=1 To 3

DepVarList(i)=i+4

Next i
 For i=1 To 4

IndepVarList(i)=i

Next i
 With newanalysis.Dialog

.Variables = Array(DepVarList,IndepVarList)

End With

The Array function in this case returns a Variant array of the list of expressions in the argument list. So you can use the Array function to set the .Variables property expecting single lists, two lists, three lists, etc.