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 below), error code, null, or array value. The following example illustrates how the Now function returns the current system date and time, which is set into a Variant variable, and thus available as string, double, long, and currency. In Statistica, select File New. In the Create New Document dialog box, select the Macro (SVB) Program tab and create a macro called Overview 3.

' This program illustrates the Variant data type;

' Variant's can be empty, numeric, currency, date,

' string, object, error code, null or array value;

' here, only the numeric, currency, and string

' identities are illustrated.

Sub Main

Dim CurrentDateAndTime As Variant

' The Now function will return the current system

' time and date.

CurrentDateAndTime = Now

AsDouble(CurrentDateAndTime)

AsLong(CurrentDateAndTime)

AsCurrency(CurrentDateAndTime)

AsString(CurrentDateAndTime)

End Sub

Sub AsDouble (x As Double)

MsgBox "x+1="+Str(x+1)

End Sub

Sub AsLong (x As Long)

MsgBox "x+1="+Str(x+1)

End Sub

Sub AsCurrency (x As Currency)

MsgBox "x+1="+Str(x+1)

End Sub

Sub AsString (x As String)

MsgBox x

End Sub

When using SVB to incorporate statistical modules (functions) into a custom program, the Variant data type is often useful when, for example, dealing with variable lists etc. For example, variables can usually be specified as strings (e.g., .Variables="MyVarName"), numbers (e.g., .Variables=2), or arrays (e.g., .Variables=VarArray). Note that variables that are not explicitly declared in the program are by default assumed to be of the Variant data type.