Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF (EN)

104 or to print out everyone whose name begins with M 500 FOR X=1 TO 5 510 J$=N$(X) 520 IF LEFT$(J$,1)="M" THEN PRINT J$ 530 NEXT All these things can only be done if the computer is able to select a position in a list and it can only do this with arrays. Note: For an explanation of how the last examples worked, see chapter 22. You will have noticed that we used the array N$(X) to store strings (the names of the people), and array Y(X) to store numbers (the years of birth). Each element of the array N$(X) can store as long a name as you want (up to 255 characters) and you can dimension to have as many entries as you want.

For example, DIM N$(1000) would create a string array with space for 1000 different names. N$(X) is called a ‘string array’ since it is used to store strings. The array Y(X) is called a ‘numeric array’ and again it can have as many elements (entries) as you need – eg DIM Y(2000) . You can also have ‘integer numeric arrays’ like DIMJ%(100) . As usual on the BBC Microcomputer the story doesn’t finish there! There is another whole group of arrays which we haven’t met yet. The arrays we have met (both string and numeric) are all ‘single-dimension arrays’ and could be illustrated by this diagram.

Y(1) Y(2) Y(3) Y(4) Y(5) 1964 1960 1950 1959 1962 Now suppose we wanted to store the day and month of the birthday as well as the year. We need more boxes. 21 12 4 24 19 2 2 2 10 12 1964 1960 1950 1959 1962 A set of data like that is called a ‘5 by 3 array’ and the (empty) boxes can be set up by the statement 10 DIM (5,3) The array could then be filled with the statements 20 Y(1,1)=21 30 Y(1,2)=2 40 Y(1,3)=1964 50 Y(2,1)=12 60 Y(2,2)=2