Arrays

Pick BASIC has two types of arrays:

  • Dynamic

    A dynamic array is a string that can be handled as a three-dimensional array based on the three main system delimiters: attribute marks, value marks, and subvalue marks. This is called dynamic because it has the ability to insert and delete array elements without having initially declared the array size.

    All elements within dynamic arrays are separated by delimiters. Dynamic arrays consist of fields (or sets of values) separated by attribute marks (char(254)). Each attribute or field in a dynamic array can consist of a number of values separated by value marks (char(253)). Each value can contain several subvalues separated by subvalue marks (char(252)).

    Dynamic arrays do not have a fixed size, nor are they predimensioned.

    Subscripts in dynamic arrays are enclosed in angle brackets (<>). Dynamic arrays are limited to three dimensions (attribute, value, and subvalue). They are called dynamic because the number of elements can increase or decrease automatically.

  • Dimensioned

    A dimensioned array is a one or two-dimensional array of separate variables. These are called dimensioned arrays due to the need to declare the number of array elements to the compiler or run time with the dim statement.

    Dimensioned arrays are also defined by the file statement. In this case, the Pick BASIC compiler dimensions the array, using the file name as the array name. It determines the number of elements in the array from the program itself and the file dictionary. The array is dimensioned based on the maximum attribute number addressed in the program, plus 1.

    Subscripts in dimensioned arrays are enclosed in parentheses.

    Dimensioned arrays are limited to two dimensions (rows and columns). Additional dimensions can be obtained by referencing dynamic arrays from elements in a dimensioned array.

    In most cases, accessing a dimensioned array is faster than accessing the same size dynamic array. A dynamic array can be an element in a dimensioned array, in which case the dynamic array subscripts are specified following the dimensioned array subscript.

    Below is a dynamic array element that has been referenced from the dimensioned array, m:

    m(a, b)< x, y, z>
    

    where

    a Row number of the dimensioned array.
    b Column number of the dimensioned array.
    x Attribute number of the dynamic array.
    y Value number of the attribute.
    z Subvalue number of the value.

    The element m(a,b) of the dimensioned array points to the beginning of the dynamic array.

    Dimensioned arrays can be redimensioned as many times as desired.

Example(s)

This loads all the item-IDs from the current master dictionary into the dimensioned array, a.

max = 100
n = 1
dim a(max)
execute "select md"
loop
readnext ID else exit
a(n) = ID
if (n >= max) then
max += 100
dim a(max)
end
n += 1
repeat