Tandy 1000 Basic Reference Manual page 63

Hide thumbs Also See for 1000:
Table of Contents

Advertisement

Chmter
61
Arrays
This is a 2-dimensional array. Each element is referred t o by 2
subscripts:
A(row,column)
For example, A(3,2) points to the third week's gas expense.
To make
a 2-dimensional array from the earlier program, add
the following lines:
2 5
FOR R
=
1 TO 4 : R E S T O R E
7 5
N E X T R
1 0 5 FOR
R
=
1 TO 4 : R E S T O R E
1 5 0 N E X T R
and change these lines:
2 0
D I M A ( 4 , 3 ) :
W
=
1
5 0
P R I N T "ENTER
T H E " ; N A M E S $ ; "
EXPENSES
I N
D O L -
6 0
I N P U T A ( R , C )
7 0
N E X T
C :
W
=
W
+
1
1 0 0 R E S T O R E : W
=
1
1 3 0 P R 1 N T : P R I N T N A M E S $ ; "
EXPENSE FOR WEEK
1 4 0 N E X T C : W
=
W
+
1
L A R S FOR WEEK NO: "W
NO:
";W;"
=
";ACR,C)
Run this program and see how it works. We simply added an-
other subscript to the original array. Now instead of referring to
an element by a row number only, we refer to it by both a row
and column number.
You can add yet another dimension, or subscript, to the array by
adding these lines:
2 2
FOR P
=
1 TO 2 :
RESTORE
7 8
W
=
1 : N E X T P
1 0 2 FOR P
=
1 TO 2 :
RESTORE
1 6 0 W
=
1 : N E X T P
and changing these lines:
20
DIM
A < 2 , 4 , 3 ) : W
=
1 : M
=
1
5 0
P R I N T "ENTER
T H E " ; N A M E S $ ; "
EXPENSE I N D O L -
6 0
I N P U T A ( P , R , C )
7 5
N E X T R :
M
=
M
+
1
1 0 0 R E S T O R E :
W
=
1 : M
=
1
1 3 0 P R 1 N T : P R I N T N A M E S $ ; "
EXPENSE FOR WEEK
1 5 0 N E X T R :
M
=
M
+
1
L A R S FOR WEEK NO:
" ; W ; "
OF MONTH NO:
" ; M
NO:
" ; W ; "
OF MONTH N O :
";M;"
=
" ; A C P , R , C )
Run the program to see how it works.
61

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents