Assignment of Arrays

Assigning an ATEasy array to another ATEasy array

In order to assign one ATEasy array or array slice to another ATEasy array or array slice, both arrays must have the same number of dimensions and all dimensions but the first must have the same size. If the array on the left side of the assignment is smaller, the array elements are assigned until the left-side array is full. If the array on the right side of the assignment is smaller, the array elements are assigned until all the elements of the right-side array have been assigned. The remaining elements of the left-side array are left unchanged.

In addition the data type of the right-side array must be assignment compatible with the data type of the left-side array, that is, it must be legal to assign a value with the right-side data type to a variable with the left-side data type. When one array is assigned to another, the effect and validity checking is precisely the same as for a series of nested loops which copy the elements one-by-one in row-major order, that is, with the right-most subscript varying most rapidly. For example, if ad1 and ad2 are both 3 by 7 arrays of Doubles, then the assignment statement

ad1 = ad2

has precisely the same effect as the following loops.

for n1=0 to 2

for n2=0 to 6

ad1[n1,n2] = ad2[n1,n2]

next

next

The following declarations and assignment statements illustrate valid and invalid assignment statements:

ad23V01: Double[2,3]

ad23V02: Double[2,3]

ad43V03: Double[4,3]

ad24V04: Double[2,4]

ac23V05: Char[2,3]

as23V06: String[2,3]

ad3V07: Double[3]

ad23V01 = ad23V02 ! OK - everything agrees

ad23V02 = ad43V03 ! OK - only first 6 Doubles (first 2 rows) will be copied

ad43V03 = ad23V01 ! OK - only first 6 Doubles (first 2 rows) of ad43V03 will be set

ad23V01 = ad24V04 ! BAD - size of 2nd dimension differs

ad23V01 = ac23V05 ! OK - A Char value can be assigned to a Double

as23V06 = ad23V02 ! BAD - A Double value cannot be assigned to a String

ad3V07 = ad23V01[1] ! OK - assign second row of ad23V01 to ad3V07

ad23V02[0] = ad3V07 ! OK - set first row of ad23V02 to values in ad3V07

Assigning an ATEasy array to a Variant

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].

Assigning a Variant to an ATEasy array

The elements from the Variant array are taken in column-major order and stored into the ATEasy array in Row-Major order until either array is exhausted.

If same number of dimensions and all but the first dimension have the same size, the "meaning" of the array is preserved as explained above, for "Assigning an ATEasy array to a Variant". If not, then as much data as possible is copied is copied in the same linear order of elements. If this is a problem, use VarGetDimCount and VarGetDimSize to verify that the array in the Variant is compatible with the ATEasy array.

See Also

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