Equinox Online Help - Language Reference - A to Z
ArraySetDimensions |
|
---|---|
Applies to | |
Syntax | ArraySetDimensions [HowExpression], ArrayItem [,VectorSizeExpression1, VectorSizeExpression2, VectorSizeExpression3, VectorSizeExpression4, AutoSizeIncrementExpression1, AutoSizeIncrementExpression2, AutoSizeIncrementExpression3, AutoSizeIncrementExpression4] |
Action | (Statement) Changes the size or alters the shape of an array. |
Scope | Usable anywhere |
Notes | Normally arrays are declared with constant values for the size of each dimension. This statement allows the size of any dimension to be changed, and the how parameter controls what will happen to the data currently contained in it. Each dimension (1 to 4) is resized to the number of elements in VectorSizeExpression1 to VectorSizeExpression4. If the parameter is missing or it contains a number less than one, the dimension is not resized. If AutoSizeIncrementExpression1 to AutoSizeIncrementExpression4 are supplied, the auto-resizing configuration of the dimension is changed. If the parameter contains zero, the dimension is set to not auto-resizable, otherwise the dimension is increased to the nearest higher multiple of that number of elements each time an item is read or written outside the array bounds. If an array dimension is declared auto-resizable (without a size inside the square brackets), the increment is initially set to one. Changing the increment to a value of more than one may lessen the number of times an array is resized and thus improve performance. However note that the array may then contain empty items on the end, which will affect sorting and searching operations. Possible values for the HowExpression parameter are:
You cannot change the number of dimensions that were declared in the array, only the number of elements in each dimension. That is because you cannot change an expression like x[2][3] to contain more or less dimensions - for example x[2][3][5]. If you need to do this, declare the array with the maximum number of dimensions you will need, and just use 1 as the number of elements of any dimensions you don't need; in the above example, declare three dimensions and use x[2][3][1] instead of x[2][3]. However, you can pass an array or vector as a parameter to a procedure which declares a different shaped array. Internally Equinox manipulates the data as a single array in row major order - in other words an array [2][3] is stored [1][1], [1][2], [1][3], [2][1], [2][2], [2][3]). If this array is passed to a procedure which declares the parameter as an array with one dimension, it would appear inside the procedure to have six elements. Alternatively if the procedure parameter was declared with three dimensions, it would appear inside the procedure as [3][2][1]. You can use the ArrayGetDimensions statement to discover how big the dimensions are. Remember that Equinox handles data type conversions automatically, so arrays declared as procedure parameters do not have to have the same type as the arguments that are passed in. Arrays that are declared dynamically (for example at the top of a procedure or form method, or after a Block statement) may be given dimension sizes using an expression containing any variable in scope. This is an alternative to the ArraySetDimensions statement (in fact, Equinox calls ArraySetDimensions on your behalf). |
Category | Arrays |
See Also | ArrayFind, ArrayFindNext, ArrayGetDimensions, ArraySearch, ArraySearchNext, ArraySort, Assert, ArrayNeg, ArrayNot, Vector, VectorSize |
Example | This example shows the effects of values 0 to 2 of the how parameter: number x[4][1], i This example prompts the user to enter a value and an index, resizes the array if necessary, and then places the value into the array. string InputData This example sets the first dimension of the array to auto-resize if more than one year's processing is required. string s[1][12] |