CSC 272 - Software II: Principles of Programming Lanaguages
Dr. R. M. Siegfried
A BASIC program to write a file of numbers
100 REM - GOSUB calls a subsroutine without passing parameters
110 DIM ARRAY(10) ' ARRAY IS AN ARRAY WITH 10 ELEMENTS
120 GOSUB 1000 ' OPEN A FILE - COMMENT AT END OF LINE
130 GOSUB 2000 ' READ IN AN ARRAY
140 GOSUB 3000 ' WRITE ARRAY ON THE SCREEN
150 GOSUB 4000 ' WRITE ARRAY IN THE FILE
200 GOTO 9990
1000 INPUT "Enter file name "; FILENAME$
1010 OPEN FILENAME$ FOR OUTPUT AS #1
1020 RETURN ' Return to the line after the gosub
2000 REM - Read in the values from the keyboard
2010 ARRAYLEN% = 0
2020 ARRAYLEN% = ARRAYLEN% + 1
2030 INPUT "Enter a value "; ARRAY(ARRAYLEN%)
2040 IF ARRAY(ARRAYLEN%) <> 0 AND ARRAYLEN% <> 10 THEN 2010
2050 REM - Get rid of the zero at then end of the array
2060 REM
2070 IF ARRAY(ARRAYLEN%) = 0 THEN ARRAYLEN% = ARRAYLEN% - 1
2080 RETURN
3000 REM - Write the array on the screen
3010 FOR I = 1 TO ARRAYLEN%
3020 PRINT "x("; I; " = "; ARRAY(I)
3030 NEXT I
3040 RETURN
4000 REM - Write the array in the file
4010 FOR I = 1 TO ARRAYLEN%
4020 PRINT #1, ARRAY(I)
4030 NEXT I
4040 RETURN
9990 CLOSE #1
9999 END
[Back to the BASIC summary]