Scripting Language Elements


Variable Types

Variant

As is the case with Visual Basic, when a variable is introduced in BlueZone Basic, it is not necessary to declare it first (see option explicit for an exception to this rule).  When a variable is used but not declared then it is implicitly declared as a variant data type.  Variants can also be declared explicitly using "As Variant" as in Dim x As Variant.  The variant data type is capable of storing numbers, strings, dates, and times.  When using a variant you do not have to explicitly convert a variable from one data type to another.  This data type conversion is handled automatically.

    Sub Main

        Dim x   ' Variant variable.

            x = 10

            x = x + 8

            x = "F" & x

        print x   ' Prints F18.

    End Sub

 

A variant variable can readily change its type and its internal representation can be determined by using the function VarType.  VarType returns a value that corresponds to the explicit data types.

SEE  VarType Function in Language Reference A - Z, for return values.

When storing numbers in variant variables, the data type used is always the most compact type possible.  For example, if you first assign a small number to the variant it will be stored as an integer.  If you then assign your variant to a number with a fractional component, it will then be stored as a double.

For doing numeric operations on a variant variable, it is sometimes necessary to determine if the value stored is a valid numeric, thus avoiding an error.  This can be done with the IsNumeric function.

Variants and Concatenation

If a string and a number are concatenated the result is a string.  To be sure your concatenation works regardless of the data type involved, use the & operator.  The & will not perform arithmetic on your numeric values it will simply concatenate them as if they were strings.

The IsEmpty function can be used to find out if a variant variable has been previously assigned.