Variant

See Also: Declaring Variables, Variable Declaration Commands, Struct, Programming with COM: Variant data types, FlexCOM Helper Functions

Purpose

Declares one or more Variant variables.

Syntax

To declare Variant variables

Variant {identifier} [… {identifier}]

Where

To declare array variables of type Variant

Variant{dimension-list} {identifier} […{identifier}]

Where

What It Does

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.

 

Examples

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.

 

Notes

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.

Example

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.