See Also: Declaring Variables, Variable Declaration Commands, Struct, Programming with COM: Variant data types, FlexCOM Helper Functions
Declares one or more Variant variables.
To declare Variant variables
Variant {identifier} [… {identifier}]
Where
Where {identifier} is the name of a new Variant variable.
{identifier} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z and _ (underscore).
To declare array variables of type Variant
Variant{dimension-list} {identifier} […{identifier}]
Where
{dimension-list} is a list of one or more array dimensions for the array. A dimension list is declared using square brackets []. One pair of brackets is used to declare each dimension. If the array is static, then you must specify the static size of each dimension between each pair of brackets. i.e. [{size}]. For more information about declaring arrays refer to Array Variable Assignments.
{identifier} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z and _ (underscore).
The variant command declares variant variables. The Variant type is capable of storing values that change type dynamically. Variables of any other type (Integer, String, Date, etc) are statically bound to that type, but a variable of the Variant type can assume values of differing types at runtime.
Multiple variables may be declared on one command line, with their names separated from each other by spaces.
A Variant type would be used in situations where the actual type of the data to be stored is unknown at compile-time. This is a common situation when writing applications that use COM objects. See FlexCOM Helper Functions for COM-specific functions.
Procedure DoTest
Variant vMyData
Move 1 To vMyData
End_Procedure
This example declares a Variant variable named vMyData and initializes it.
Variant[] vVariantData
This example declares 1 dynamic array variable, named vVariantData, containing an undefined number of elements of type Variant.
Variant[5] vVariantData
This example declares 1 static array variable, named vVariantData, containing 5 of elements of type Variant.
Variant[][3] vVariantData
This example creates a two-dimensional dynamic array variable named vVariantData, containing an undefined number of elements of type Variant. Conceptually, this represents a rectangular array with an undefined number of rows, each of 3 columns.
You can declare dynamic multi-dimensional arrays where all dimensions are dynamic; these are called jagged arrays.
When assigning a Variant variable that was passed as a byref parameter to another Variant variable, the reference is assigned instead of the value of the referenced variable. This is by design; variants are designed to hold references to other data types. To pass a value by value instead of by reference, you cannot use the Variant data type.
Procedure Foo Variant BYREF vPassed
Variant vInside
Move vPassed To vInside
Move (Uppercase (vInside)) To vInside
:
End_Procedure
:
Send Foo (&vMyName)
In the above situation, vInside is not a copy of the value in vPassed, but the same variable. That means that the uppercase operation not only changes the value of vInside, but also vPassed. If this is not desired, use a string or other appropriate data type to pass as byref parameter.
The special Variant value OLE_VT_EMPTY is used to indicate that a Variant has not yet been assigned any value. Variant.pkg must be Used to use OLE_VT_EMPTY.
If you need to define a global Variant variable, you should use the global_variable command to do so.