Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Declaring arrays – PB Docs 126 – PowerBuilder Library

Declaring arrays – PB Docs 126

Declaring arrays

Description

An array is an indexed collection of elements of a single
datatype. In PowerBuilder, an array can have one or more dimensions.
One-dimensional arrays can have a fixed or variable size; multidimensional
arrays always have a fixed size. Each dimension of an array can
have 2,147,483,647 bytes of elements.

Any simple variable declaration becomes an array when you
specify brackets after the variable name. For fixed-size arrays,
you specify the sizes of the dimensions inside those brackets.

Syntax

The following table describes the parameters used to declare
array variables.

Table 3-6: Array variable declaration parameters

Parameter

Description

access
(optional)

(For instance variables only) Keywords
specifying the access for the variable. For information, see “Access for instance variables”.

datatype

The datatype of the variable. You can
specify a standard datatype, a system object, or a previously defined
structure.

For decimals, you can specify the precision of the data by including
an optional value in brackets after datatype (see “Syntax of a variable declaration”):

For blobs, fixed-length blobs within an array are not supported. If
you specify a size after datatype, it is ignored.

variablename

The name of the variable (name must be
a valid PowerScript identifier, as described in “Identifier names “).

You can define additional arrays with the same datatype by naming
additional variable names with brackets and optional value lists,
separated by commas.

[ { d1,
…, dn } ]

Brackets and (for fixed-size arrays)
one or more integer values (d1 through dn,
one for each dimension) specifying the sizes of the dimensions.

For a variable-size array, which is always one-dimensional, specify
brackets only.

For more information on how variable-size arrays
change size, see “Size of variable-size arrays”.

For a fixed-size array, the number of dimensions is determined by
the number of integers you specify and is limited only by the amount
of available memory.

For fixed-size arrays, you can use TO to
specify a range of element numbers (instead of a dimension size)
for one or more of the dimensions. Specifying TO allows
you to change the lower bound of the dimension (upperbound must
be greater than lowbound):

{ valuelist }
(optional)

A list of initial values for each position
of the array. The values are separated by commas and the whole list
is enclosed in braces. The number of values cannot be greater than
the number of positions in the array. The datatype of the values must
match datatype.

Examples

These declarations create variable-size arrays:

This statement declares a variable-size array of decimal number
(the declaration does not specify a precision, so each element in
the array takes the precision of the value assigned to it):

Fixed arrays

These declarations create fixed-size, one-dimensional arrays:

Using TO to change array index values

These fixed-size arrays use TO to change
the range of index values for the array:

Incorrect declarations using TO

In an array dimension, the second number must be greater than
the first. These declarations are invalid:

Arrays with two or more dimensions

This declaration creates a six–element, two-dimensional
integer array. The individual elements are li_score[1,1], li_score[1,2], li_score[1,3], li_score[2,1], li_score[2,2],
and li_score[2,3]:

This declaration specifies that the indexes for the dimensions
are 1 to 5 and 10 to 25:

This declaration creates a 3-dimensional 45,000-element array:

This declaration changes the subscript range for the second
and third dimension:

More declarations of multidimensional arrays:

This declaration creates three decimal arrays:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x