Values for array elements

General information

PowerBuilder initializes each element of an array to the same default value as its underlying datatype. For example, in a newly declared integer array:

integer li_TaxCode[3]

the elements li_TaxCode[1], li_TaxCode[2], and li_TaxCode[3] are all initialized to zero.

For information about default values for basic datatypes, see “Initial values for variables”.

Simple array

In a simple array, you can override the default values by initializing the elements of the array when you declare the array. You specify the values in a comma-separated list of values enclosed in braces. You do not have to initialize all the elements of the array, but you cannot initialize values in the middle or end without initializing the first elements.

Multidimensional array

In a multidimensional array, you still provide the values in a simple, comma-separated list. When the values are assigned to array positions, the first dimension is the fastest-varying dimension, and the last dimension is the slowest-varying. In other words, the values are assigned to array positions by looping over all the values of the first dimension for each value of the second dimension, then looping over all the values of the second dimension for each value of the third, and so on.

NoteAssigning values You can assign values to an array after declaring it using the same syntax of a list of values within braces:

integer li_Arr[]
Li_Arr = {1, 2, 3, 4}

Examples

Example 1 This statement declares an initialized one-dimensional array of three variables:

real lr_Rate[3]={1.20, 2.40, 4.80}

Example 2 This statement initializes a two-dimensional array:

integer li_units[3,4] = {1,2,3, 1,2,3, 1,2,3, 1,2,3}

As a result:

Example 3 This statement initializes the first half of a 3-dimensional array:

integer li_units[3,4,2] = &

 {1,2,3, 1,2,3, 1,2,3, 1,2,3}

As a result: