CHAPTER VIII

Arrays, the next subject to be discussed, are an essential  element 
of programming.  Thus far, letters have been assigned to  variables 
and there has been no particular order in saving or 
handling them.  For complex programs, this system would become 
unmanageable.  ADAM recognizes only the first two characters of a 
variable and the first character must be a letter.

An array is named and described as to type and size through the 
use of a DIM or Dimension Statement.  The name of the array is 
governed by the same rules as the name of a variable as was 
presented earlier.  The first character must be a letter and only 
the first two characters are recognized.  It can be described as  a 
numerical array, an array of just whole numbers if % is added 
after the name, or a string array if a $ is added after the name. 
The statement 

 DIM ax (14,32,12)

for example translates that the array known as ax is an array of 
numbers that are decimal numbers and it has 14 rows, 32 columns 
and 12 pages.  If one column and one page were required, the 
statement would have been

 DIM ax (14)

Only one page would result if the following were used:

 DIM ax(14,32)

When an array is diminsioned, the results may be more than 
expected.  Were DIM ax(14,32) specified, the first row would have 
been numbered 0 and the last 14.  Columns would have been 0 for 
the first one and 32 for the last.  In other words we actually  got 
15 rows and 33 columns.  This can be useful.  For example, to 
start with a beginning balance in column 3, set row 0, column 3 
equal to the starting balance and check number 1 will be in row  1.

All the operations performed with elements of an array can be 
performed with variables.  Arrays are useful for storing 
information as the information can be reviewed through use of 
FOR/NEXT statements and the data can be transfered in an orderly 
fashion for storing on tape or disk.

Types of data in the same array cannot be mixed.  If there is a 
string array, all the data in it must be strings ($).  Likewise, 
if there is an integer array (%) all the information must be 
integers.

If a value is assigned to the element of an array in a program 
before DIMENSIONING the array, the computer will presume that it 
was a ten-element array thus (8,5) can be assigned, column 5 in 
row 8 but not a(14,3), ADAM can't go past 10.

Having once DIMENSIONED an array, you can not redimension it. 
When trying to assign an element of an array a value (it will 
automatically assume the 10-element situation.  An error message 
will be received i trying to execute a DIMENSION statement.

An early statement number in a program as the DIMINSION statement 
will avoid the error difficulty.  The numbers below 100 in most 
programs are reserved for REM statements describing the program, 
dimensioning of arrays, and assigning system variables, things 
that will apply throughout the program.  The DIMENSION Statement 
looks like:

 DIM ants (6,23), b$(32), cost%(15,12) etc.

To return to a dimension statement and add arrays while writing a 
program each one must be seperated by a coma.

To illustrate the use of arrays, make a listing of members of a 
group with their family name, given name or initials, street 
address, city and state.  The array will need five columns.   Allow 
for 100 menbers.  AT first use DATA/READ statements for the 
information, but this is for convenience at this time only.

There is a separate column for given name or initials.  It is 
conventional to use listing such as

 Jones, J.  A.
 Jones, John C.

When handling data in any BASIC dialect, the comma causes  problems 
and as a minimum, the material following the comma gets  lost as 
the comma indicates the end of a piece of data.  Refer to 
discussion on DATA statements.  As long as the data is not going 
to be stored in a file, the comma can be tolerated if it is part 
of a string inside quotation marks.  Things get confused,  however, 
coming back out of a data file.

Beyond convention, if the list is to be sorted, last name first  is 
essential.

Type this program:

 10 REM gHaaug members listing
 20 dim me$(100,5)
 30 DATA Carvaljal, Arthur L., 309 Briar Walk Drive, Porter, 
  Texas
 31 DATA Cobb, C.  P., P.O.  BOX 1333, Wimberly, Texas
 32 DATA Culbertson, Charles R., 2205 28th St., Texas City, Texas
 33 DATA Meyers, Daniel L., 14015 Cedar Hill, San Antonio, Texas
 34 DATA Finn, David, 4801 12th St., Baycliff, Texas
 35 DATA Cornter, Eugene, 7723 DeMoss, Houston, Texas
 36 DATA Biggs, James N., 7016 Putt Lane, Fort Wayne, Indiana 

 50 for i = 1 to 7:  for j = 1 to 5
 60 READ me$(i,j)
 70 NEXT:  NEXT
 500 END

What has been done to this point has been to enter into column 1 
of the array, the person's family name, column 2 the given name  or 
initials, column 3 street address, column 4 the city and  column 5 
the state.  That proceedure was used for each value of i  by 
varying j from 1 to four.  The range for i was set by the fact 
that there were seven names.  It could have been handled through  a 
procedure known as error trapping, but that will be covered  later.

RUN the program.  To prove that it worked, ENTER in the immediate 
mode the following command:

 for J = 1 to 5:  ? me$(4,j):  next

Upon pressing RETURN, the data on the fourth person entered  should 
appear.  Type it.

To see all the peoples' names -- ENTER:

 for i = 1 to 7:  ? me$(i,1); ", "; me$(i,2):  NEXT

There is a the difference.  In the first example, a printout of 
all the columns for row 4 was requested.  In the second a  printout 
of all of the information in column 1 and 2 was 
requested.

Type these steps in the immediate mode:

 speed = 50
 for i = 1 to 7:  ? me$(i,1); ", "; me$(i,2):  for j = 3 to 5:  ? 
  me$(i,j):next:  ? :  next
 speed = 255

Save this program for future use.


