Size of variable-size arrays

General information

A variable-size array consists of a variable name followed by square brackets but no number. PowerBuilder defines the array elements by use at execution time (subject only to memory constraints). Only one-dimensional arrays can be variable-size arrays.

Because you do not declare the size, you cannot use the TO notation to change the lower bound of the array, so the lower bound of a variable-size array is always 1.

NoteUsing arrays with a TO clause in EAServer components When you generate a proxy for an EAServer component deployed from PowerBuilder that contains an array that uses a TO clause, the proxy object represents the range as a single value because CORBA IDL does not support the TO clause. For example, Int ar1[5 TO 10] is represented as Int ar1[6], with [6] representing the number of array elements. Client applications must declare the array using a single value instead of a range.

How memory is allocated

Initializing elements of a variable-size array allocates memory for those elements. You specify initial values just as you do for fixed-size arrays, by listing the values in braces. The following statement sets code[1] equal to 11, code[2] equal to 242, and code[3] equal to 27. The array has a size of 3 initially, but the size will change if you assign values to higher positions:

integer li_code[ ]={11,242,27}

For example, these statements declare a variable-size array and assigns values to three array elements:

long ll_price[ ]

ll_price[100] = 2000

ll_price[50]  = 3000

ll_price[110] = 5000

When these statements first execute, they allocate memory as follows: