The program:
! MExample Program 8-9
! Fill an array from a text file and
! print the array in a formatted display.
! Check that the file contains 15 values.
! try bad.dat and numbers.dat since the first fails and the second succeeds
! make operation automatic by putting program to read the files in a loop
DO until flag = 1
LET flag = 0
DIM Table(1 to 3, 1 to 5)
! Open a file and check its contents.
!INPUT prompt "File name? ": FileName$
LET FileName$ = "BAD.DAT"
PRINT "The file is named ";FileName$
DO until Count >= 15 or Ucase$(FileName$[1:1]) = "Q"
LET Count = 0
OPEN #1: name FileName$
DO until End #1
INPUT #1: Value
LET Count = Count + 1
LOOP
IF Count < 15 then
SET COLOR "red"
PRINT "This file does not contain enough data."
!PRINT "Enter a new file name or type Q to stop."
CLOSE #1
! INPUT prompt "File name? ": FileName$
LET FileName$= "numbers.dat"
SET COLOR "green"
PRINT "The file is named ";FileName$
LET flag = 1
END IF
LOOP
! Fill an array from a text file.
RESET #1: begin
FOR Row = 1 to 3
FOR Column = 1 to 5
INPUT #1: Table(Row, Column)
NEXT Column
NEXT Row
! Display the filled array.
FOR Row = 1 to 3
FOR Column = 1 to 5
PRINT Table(Row, Column);
NEXT Column
NEXT Row
LOOP
PAUSE 4
SOUND 1000,.1
SET COLOR "blue"
PRINT "goodbye!"
PAUSE 4
END
The output:
The file is named BAD.DAT
This file does not contain enough data.
The file is named numbers.dat
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
goodbye!