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.
Using 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.
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:
The statement ll_price[100]=2000
will
allocate memory for 100 long numbers ll_price[1] to ll_price[100],
then assign 0 (the default for numbers) to ll_price[1] through ll_price[99] and
assign 2000 to ll_price[100].
The statement ll_price[50]=3000
will
not allocate more memory but will assign the value 3000 to the 50th
element of the ll_price array.
The statement ll_price[110]=5000
will
allocate memory for 10 more long numbers named ll_price[101] to ll_price[110] and
then assign 0 (the default for numbers) to ll_price[101] through ll_price[109] and
assign 5000 to ll_price[110].