to enter a DIM statement for %m will produce an audible tone and entering the statement will not be successful.

If we need to use an integer array with more than 64 elements, it is possible although what changes is the way we have to address them. Whereas in a normal integer array the subscript is written inside parentheses () for integer arrays larger-than-64-elements, the subscript is written within brackets []. Furthermore, larger-than-64-elements integer arrays reduce the number of available integer arrays in the system as they take the entire array that follows sequentially from the one we're using and attach it to the current one. What this means is that if we want to use a 128 element integer array %a[], this will take the space from integer array %b(). If we want to use an 192 element integer array %c[], this will use space from integer arrays %d() and %e() and so on.

The maximum integer array usable is 26 x 64 =1664 if using integer array %a[] with no other arrays available. Note that subsequent arrays don't disappear; they're still accessible carrying data from the integer array that reserved them. Modifying them however may have unexpected consequences. To illustrate this point, let's assume an integer array %a[] with a desired 128 elements. Write the following little program:

10 %a[65] = 43
20 PRINT %a[65]
30 PRINT %b(1): REM the 65th
   element of array a[] is
   b(1)

It's now obvious how this works!

You can also set up arrays with more than one dimension. This does also apply to Integer Arrays, although they're normally predefined to have a single dimension; you'll see how below. In a two-dimensional array you need two numbers to specify one of the elements – rather like the line and column numbers to specify a character position on the television screen – so it has the form of a table or matrix.

Alternatively, if you imagine the line and column numbers (two dimensions) as referring to a printed page, you could have an extra dimension for the page numbers. Of course, we are talking about numeric arrays; so the elements would not be printed characters as in a book, but numbers. Think of the elements of a three-dimensional array v as being specified by v (page number, line number, column number).

For example, to set up a two-dimensional array c with dimensions 3 and 6, you use a DIM statement:

DIM c(3,6)

This then gives you 3 x 6=18 subscripted variables:

1 2 3 4 5 6
1 c(1,1) c(1,2) c(1,3) c(1,4) c(1,5) c(1,6)
2 c(2,1) c(2,2) c(2,3) c(2,4) c(2,5) c(2,6)
3 c(3,1) c(3,2) c(3,3) c(3,4) c(3,5) c(3,6)

Table 3 – Representation of a two-dimensional array

The same principle works for any number of dimensions.

Although you can have a number and an array with the same name, you cannot have two arrays with the same name, even if they have different numbers of dimensions except in the case of normal numerical and integer arrays.


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.