Introducing Arrays.

When it comes time to store multiple values into a single variable, we have two choices:

1. Use an array variable
2. Use a linked-list variable

We will use the array variable for now since we will review the linked-list variable type in a later tutorial. PPL offers many ways to work with array variables, including arrays of different sizes and arrays of strings.

Arrays can be defined on local or global variables. To define an array, PPL comes with multiple functions to help you do this.

Dim(var$, 10);

This will create an array of 10 elements of the default type TDOUBLE (8 bytes) for variable var$. To declare multi-dimensional arrays, do the following:

Dim(var$, 10, 10, 10);

You can later access arrays just like other variables by specifying an offset within brakets [].

Dim(var$, 10, 10);
var$[0, 0] = 102.24;
var$[9, 9] = 23.2873;

Notice that we use 0,0. Arrays offsets start at 0 and goes to the array size – 1. If your array size is 10, 10, then the minimum offset if 0,0 and the maximum offset is 9,9. To create arrays with custom element sizes, use SDIM().

SDIM(var$, TBYTE, 10, 10);

This will create an array of 10, 10 elements of type TBYTE (1 byte).

Now, what about strings? You will be happy to hear that PPL handles strings transparently with just a little twist. PPL stores only the string pointer address in the array's elements. Therefore the use of the @ operator is required to retrieve the string when accessing an array element.

Dim(var$, 10);
var$[2] = "Jack Bower";
var$[3] = "Joe Bloe";
ShowMessage(@var$[2] % " " % @var$[3]);