VarDimSize Procedure

Returns or sets the number of elements of the specified dimension in an array variant.

Syntax

[ lDimSize = ] VarDimSize ( pv [, lDim [, lRedimSize])

The VarDimSize procedure syntax has the following parts:

 

Name

Type

Description

lDimSize

Long

The number of elements of the specified dimension

pv

Var Variant

A variant variable that contains an array

lDim

[Val] Long = 0

Optional. The dimension number, 0 based

lRedimSize

[Val] Long = 0

v9. Optional. New size (must be greater than 0 when redim). Only the least significant dimension size can be changed.

Comments

If the data in the given Variant is not an array, then the function returns 0. If the data is an array, but the array has no dimension or it does not have the dimension specified, then the function also returns 0.

Variant arrays are stored in memory in different order than ATEasy or C based arrays. For example 2 rows 3 columns is stored: [0, 0], [1, 0], [0, 1], [1, 1], [0, 2], [1, 2]. In ATEasy it will be store: [0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2].  Assigning ATEasy array to a variant or vise versa will convert the order of element in memory correctly.

When using the function to change the dimension of an array, the array data is preserved.

Example

! For example, vr is a Variant and anArray[2, 3] is a 2 rows 3 columns Short array

anArray={{1, 2, 3}, {4, 5, 6}}

vr=anArray

print VarDimSize(vr, 0) ! Returns 2

print VarDimSize(vr, 1) ! Returns 3

! the following case returns 0 because it has no such dimension, 2

print VarDimSize(vr, 2)

 

VarDimSize(vr, 0, 4)    ! we now have 4 columns instead of 3 (v9 or above)

vr[0, 3]=7

Redim Preserve anArray[2, 4]

anArray=vr

print anArray[0, 3]     ! print 7

See Also

GetDimCount, sizeof operator, VarType, Variant Data Type