Data - AMSTRAD CPC464 User Manual

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
Table of Contents

Advertisement

We can now write the framework for a subroutine to deal a card:
1 0 D I M P A C K ( 5 2 )
2 0 F O R X = 1 T O 5 2
3 0 L E T P A C K ( X ) = 0
4 0 N E X T X
. . . . . . . . . . . .
1 0 0 0 C A R D = I N T ( R N D * 5 2 ) + 1
1 0 1 0 I F P A C K ( C A R D ) = 1 T H E N G O T O 1 0 0 0
1 0 2 0 P A C K ( C A R D ) = 1
1 0 3 0 R E T U R N
Note that the DIM statement is the first line in the program . This is because an array can only be
dimensioned once - it cannot be redimensioned further on in the program.
Lines 20 to 40 set the elements of the array to zero. The subroutine that starts at line 1000 then
chooses a card at random and checks that it has not been already dealt. If it has, then another is
chosen until one is found that is still in the deck . The routine then changes the value of the
appropriate element in the array to signify that the card has now been dealt and returns from the
subroutine.
Array handling is not restricted to single dimensions but can be extended to any number of
dimensions desired. This is achieved by simply adding further reference numbers to the variable. For
example a 10x10x10 array (or matrix) can be set up by the command:
D I M A R R A Y ( 1 0 , 1 0 , 1 0 )
This technique is useful for dividing data into smaller subsets within a large group.
In our example we could split the pack into four suits of thirteen cards which can then be accessed
separately by using the format:
D I M P A C K ( 4 , 1 3 )
if we wish to find the four of clubs,which might have been element 43 in our original array, we
Now
simply have to examine element (2,4) - assuming that clubs are the second ' row' in our new array.
Arrays do not have to be used to store numerical data but can be used to handle strings as well . An
application for this might be to record the names of people booked into seats at a theatre or on an
aeroplane flight.

4.12 DATA

This command, in conjunction with the command READ, can be used to input data into a program.
The required data is listed in a line with each item separated by a comma and the whole list
preceeded by the DATA command. The data can now be accessed sequentially using the READ
command.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents