208 DIM dimension of an array Purpose As well as simple numeric and string variables (such as ‘X’ and ‘name$’) it is possible to work with ‘arrays’ of variables. These are extremely useful when working with groups of numbers or words. For example if you wanted to work with a set of information about the rooms in a hotel with four floors, each with 30 rooms, then an array of four by 230 entries can be created like this: DIM hotel(4,30) Having set up an array, one can enter information into each of its ‘elements’.
For example the cost of the room per night might be Ј26.50 hotel(1,22)=26.50 hotel(4,1)=165.00 In practice the statement DIM hotel(4,30) produces an array of five by 31 entries since the lowest array element is hotel(0,0) . All the above arrays are called ‘two dimension numeric arrays’. Another array could contain the names of guests: DIM name$(4,30) name$(1,22)="Fred Smith" name$(4,1)="The Queen" That sort of array is called a ‘two dimension string array’. Arrays may have one or more dimensions. A single dimension array would be appropriate for all the houses in a road, eg DIM MainSt(150) That sort of array is called a ‘single dimension numeric array’.
All arrays are normally dimensioned very early in the program. It is ‘illegal’ to attempt to change the size of an array by re-dimensioning it later in the program. An array may have as many dimensions and as many elements in each dimension as the computer has space for – but you tend to run out of computer memory pretty fast with large arrays! It is essential that there is no space between the array name and the first parenthesis. Thus DIM A(10) is correct but DIM A (10) will not define an array.