User`s manual
This is how the record lel1gth is determined. We would probably want to
allow an extra character in length for each field, to allow for separations;
otherwise the INPUT# command would pick up a much longer piece of the file
than needed, just like in sequential files. Therefore, we'll set up a file with a
length of 108 characters per record. In the first record, we'll put the number 1,
representing the largest record# used so far. Here is the program as described so
far:
10 OPEN I, 8, 15
20 OPEN 2, 8, 3, "O:MAILINGLlST,L,"+CHR$(108)
30 GOSUB900
40 PRINT# I, "p" CHR$(3) (CHR$(l) CHR$(O)CHRS(l)
50 GOSUB900
60 IF E=50 THEN PRINT#2, I: GOTO 40
70 INPUT# 2, X
300 STOP
900 INPUT# I, E, B$, C, D
910 IF (E=50) OR(E < 20) THEN RETURN
920 PRINT A; B;C; D: STOP: RETURN
Error #50 which is checked in line 60 of the program is the RECORD
NOT PRESENT error, which means that the record hadn't been created yet.
Writing into the record will solve the proglem. This error condition must be
watched carefully within your programs.
So far, all it does is create the file and the first record, but doesn't actually
put any data in it. Below is a greatly expanded version of the program, to
actually allow you to work with a mailing list where the records are coded by
numbers.
MAILING LIST READ AND WRITE PROGRAM:
5 A(I) =12:A(2) =15:A(3) =20:A(4) =20:A(5) = 12:A(6) =2:A(7) =9:A(8) =10
10 OPENI,8,15:0PEN2,8.3,"0:Mailing List,l ,"+CHRS(108):GOSUB900
20 PRINT#I ,"p"CHRS(3)CHRS(I) CHRS(O) CHRS(1 ):INPUT#2,X
30 INPUT'Read, Writ., or End..JS:IFJS= THENCLOSE2:CLOSEI:END
40 IFJS="w"THEN200
50 PRINT:INPUT"R.cord #":R:IFR<00RR>XTHEN50
60 IFR<2THEN30
70 RI=R:R2=0:IFRI > 256THENR2=INT(RI/256):RI=RI.256°R2
80 RESTORE:DA TI,FI RST NAME,14,LAST NAME,30,ADDRESSI ,51,ADDRESS2
90 DATA72,CITY ,85,5T ATE.88.ZIP.98.PHONE#
100 FORL=I T08:READA,AS:PRlNT#1 ,"p"CHRS(IJ) CHRS(RI) CHRS(R2) CHRS(A):GOSUB900
110 ONA/50GOT050:INPUT#2,ZS:PRlNTAS,ZS:NEXT:GOT050
200 PRlNT:INPUT'R.cord #":R:IFR<OORR>5000TlIEN200
210 IFR<2THEN30
215 IFR> XTHENR=X+ I :PRINT:PRINT"Record# "R
220 RI=R:R2=0:IFRI >256THENR2=INT(RI/256) :RI=RI
- 256°R2
230 RESTORE: FORL= 1T08: READA,AS:PRlNT#I, "p"CHRS(3) CHRS(RI) CHRS(R2) CHRS(A)
240 PRINTA$,:INPUTZ$:IFLEN(ZS) > A(L)THENZS=LEFT$(ZS.A(L»
245 PRlNT#2,ZS:NEXT:X=R:PRINT#1 ,"p"CHRS(3) CHRS(I) CHRS(O)
250 PRlNT#2,X:GOT0200
900 INPUT#I ,A,BS,C.D:IF A < 20THENRETURN
910 IF A < > 50THENPRINT A:BS,C;D:STOP: RETURN
920 IFJS="r"THENPRINTBS
930 RETURN
36
" ..