How Do I Assign a Value to a Variable?

Assignment in STATISTICA Visual Basic is used via the = operator. For example:

Dim Number As Integer

Number = 5

The above example assigns the value 5 to an integer variable called Number.

There are a few stipulations in regards to assignments being valid:

Variable data type and assignment value must match
The value that you are assigning to a variable must be appropriate in terms of data type. The following example demonstrates a string value incorrectly being assigned to a double-precision variable:

Dim Number As Double
 'The following assignment is invalid
 Number = "Text"

This will not run because a double-precision variable cannot hold a text string. In this example a String variable is recommended, as demonstrated here:

Dim TextString As String
 TextString = "Text"

Assignment value must be within the variable's data-type range
When a value which is too large is assigned to a variable, an overflow error will be encountered. The following demonstrates such a situation:

Dim Number As Integer
 'The following is out of range
 Number = 2000000

Because the largest integer that an Integer can hold is 32,767, then Number will not be able to handle a value such as 2,000,000. For this example a long-integer data type is recommended, as demonstrated below:

Dim Number As Long
 Number = 2000000

Constants cannot have values assigned to them
Constant variables are the only type of variable that may not have their values changed. Once a constant has been initialized, that value will remain associated with the constant for the duration of your program. The following demonstrates the use of a constant variable:

'Invalid, must be initialized
 Const MyFavoriteNumber
 'Now it's OK
 Const MyFavoriteNumber = 7
 'Invalid, cannot change the value of a constant
 MyFavoriteNumber = 9