Arrays and Variants

Arrays of Variants

An array of variants can be used to collect data items of different types as each variant can contain any of the standard kinds of variant data, including an ATEasy array. If av is an array of 5 variants, then av[0] could contain the string "XYZ", av[1] could contain the short integer 12345, av[2] could contain the double 3.14159, av[3] could contain a reference to an ACheckBox control, and av[4] could contain a 10 by 20 array of floats.

Variants Containing Arrays

An ATEasy array with any number of dimensions can be assigned to a variable or array element of type Variant. Since the parser cannot know what is contained in a Variant value, it allows any Variant value to be subscripted with any number of subscripts. When the reference to the presumed array element is evaluated at run time, it is verified that the Variant contains an array, that the number of subscripts is less than or equal to the number of dimensions in the contained array, and that the value of each subscript is within the proper range. A run time error occurs if any of these conditions is violated.

The ATEasy code which accesses the elements of an ATEasy array which has been stored in a Variant needs to know how many dimensions there are, the size of each dimension, and the type of the array elements. There are three routines in the Internal library which can be used to determine the needed information :

In the most cases the code storing the ATEasy array into the Variant will be in close agreement with the code which processes the Variant and the above routines would be used to verify that no mistake was made in creating the Variant.

Row-major Versus Column-major Order

Visual Basic and ActiveX controls assume that arrays are stored in column-major order, that is, the first subscript varies most rapidly. When an ATEasy array is assigned to a Variant or vice versa, the element order is rearranged from row-major order to column-major order, and vice versa. This means that if an ATEasy array is assigned to a Variant and passed to a method of an ActiveX control written in Visual Basic, a subscripted reference to any array element in the Visual Basic code refers to the very same element value as an ATEasy subscripted reference to the original data with the exact same list of subscripts. For example, if anPoints is a 10 by 2 array of shorts representing 10 X-Y screen positions, both the ATEasy code and the Visual Basic code refer to the Y coordinate of the 5th point as anPoints[4,1].

Effect of Subscripting in Arrays of Variants Which Themselves Contain Arrays

If an ATEasy array of Variants is subscripted using more subscripts than the number of dimensions of the Variant array, it is presumed that the referenced Variant element contains an array and that the extra subscripts are to be used to index into that array. If a n-dimensional array of Variants is assumed to contain a m-dimensional array in each Variant, the effect of subscripting the Variant array with differing numbers of subscripts is given below:

 

Subscripts

Description

1 to n-1 subscripts

A slice of the Variant array

n subscripts

A Variant (which contains a m-dimensional array)

n+1 to n+m-1 subscripts

A slice of the array contained in the referenced Variant element

n+m subscripts

A basic element of the array contained in the referenced Variant element

See Also

Arrays (Definition), Arrays and Structs, Arrays as Procedure Arguments, Assignment of Arrays, Multiple Dimensions of Arrays, Strings as Arrays