Array Data Types

It is often useful to treat a set of variables as a group.  This lets you perform repetitive operations more easily.  An array is a group of string or numeric data sharing the same variable name.  The individual values that make up an array are called elements.  An element of an array can be used in a statement or expression wherever you would use a regular string or numeric variable.  In other words, each element of an array is itself a variable.

PowerBASIC provides several statements that perform operations on an array as a whole, allowing you to sort its contents, scan its contents for data that matches a certain condition, and insert data into or delete data from the existing structure.

You can think of an array as a row of boxes, numbered from zero to a predetermined number: four, in the example figure below.  Each box holds a distinct value, which may or may not differ from the values in the other boxes.  The boxes and their numbers are represented by parentheses surrounding a number; for example, item%(3) represents box number three of the array item%.  Thus, if the value held within box number 3 is 1952, the statement total%=item%(3) would place the value 1952 into the variable total%.

Dimensioning a dynamic array with DIM or REDIM also clears each element, unless the PRESERVE option is present.  Each element of each numeric array is set to zero; string arrays are set to the null string ("", length zero).  Declaring the name and type of an array, as well as the number and organization of its elements, is performed by the DIM statement.  For example:

DIM payments(55) AS CURRENCYX

…creates an array variable payments, consisting of 56 Extended-currency elements, numbered 0 through 55.  Array payments and an Extended-currency variable also named payments are separate variables. If this is confusing, you'll understand why we suggest that you use different variable names.

 

See Also

Subscripts

String arrays

Multidimensional arrays

Array storage requirements

Internal representations of arrays

Arrays within User-Defined Types

Array operations