P725 CEEFAX 725 Mon 10 Nov 21:12/44 |B2201205|a16FRjadT|i24BBBC332k|l43000|p ÷e DISK NUMBER : DISK CATEGORY : DISC÷e FILENAME : F.READ-T÷e ÷e ÷e MACHINE BBC B/ B+/Master÷e BASIC 1 or 2÷e Any OS, Any DOS÷e PER IPHERALS Disc Drives÷e TAPE COMPATIBILITY No÷e ÷e ÷e LINENUMBER 20640-20770, 20950,21090÷e N AME FNread(rec% ,f%)÷e ÷e ÷e AUTHOR J. Meets÷e REFEREN CE Random Access Rot tines÷e ÷e CLASSIFICATION Disc Random Access÷e DESCRI PTJON Gets a specified record into memory ÷e÷a÷a and reads the required field.÷e ÷e PARAMETERS REQUIRED rec|c
P725 CEEFAX 725 Mon 10 Nov 21:21/31 |B2202205|b16FReadT|i24BBBC332k|l43353|p % 4 digit record number.÷e f% field number.÷e÷ j PARAMETERS RJTU5NED Rjqu ired field as a text string.÷e If read fails t hen the string "ERROR"÷e ÷e GLOB AL VARIABLES Rmax% Max number of records held÷e in memory.÷ j rw% read/write flag.÷e R$(Rmax%) Array for r ecords in memory.÷e len*(20) Array for length s of fields.÷e handle% Handle for opened jil e.÷e l ats% Last valid record number.÷e÷e ÷e MODE DEPENDENCE None÷e ÷e OTHER MODULES CALLED Uses FNstart, FNF#get÷e OTHE R MODULES RELATED include F.|c
P725 CEEFAX 725 Mon 10 Nov 21:18/53 |B2203205}a1vFRjadT|j24BBBC332k|l436AD|p INIT, F.WRJTJ÷e ÷e COMMENTS This procedure checks f or possible ÷e error conditions, then uses FMs tart÷ito find the offset to the start of the required field. FNF#get is then÷eu sid to get the record into memory. Final ly the required field is÷esjparated out using MID$.÷eFNstart runs through the le n* array to calculate the start of the f ield.÷eIt also calculates the record len gth rlen* and file offset head%, and÷ech ecus that the field requested exists.÷eF NF#get maintains several records in mjm ory as text strings in R$(Rmax%).÷eIf th e required record is not in memory then the file pointer is÷ecalculated and the record read in. A final check is made t hat the correct÷erecord has been retriev ed.÷e÷e ÷e TYPICAL CALL AND LISTIVG÷e÷e 10 REM Random File Routines÷e 20 :|c
P725 CEEFAX 725 Mon 10 Nov 21:11/14 |B2204205}b1vFRjadT|i24BBBC332k|l43A06|p ÷e 30 REM Initialisj÷e 40 PROCF#Init ("test",2)÷e 50 :÷e 60 REM Read feel d 2 in record 1004÷e 70 PRINT FNread(1 004,2)÷e 110 :÷e 120 EVD÷e Q30 :÷e206 40 REM *****************************÷e20 6u0 REM * *÷e2 0660 REM * Random File Read *÷e 20670 REM * (c) 1986 J. Meets *÷ j20680 REM * Prestel Mailbox 707327277 * ÷e20690 REM * *÷e20700 REM *************************** **÷e20710 :÷e20720 REM Read Record Mum, Field÷e20730 DEF FNread(rec%,f%):LOCAL s t%,rlen%,head%÷e20740 IF rec%<1000 OR re cI>last% OR rw%<1 THEN="ERROR"÷e20750 st %=FNstart(e%):IF st%=0 THEN="ERROR"÷e207 v0 =MID$(R$(FNF#get(rec%)),st%,len*(f%)) ÷e20770 :÷e20950 REM Get the field start , also calc the record length and file o ffset÷e20960 DEF FNstart(f%):LOCAL i%,st %÷e20970 rlin%=1:i%=0:REPEAT÷e20980 IF i%<f% THEN st%=st%+len%(i%)÷e20990 |c
P725 CEEFAX 725 Mon 10 Nov 21:14/38 |B220u205}b16FRjadT|j24BBBC332k|l43D57|p rlen*=rlen*+len*(i%)÷e21000 i%=i%+1: UNTIL lin*(i%)=0÷e21010 IF f%>=i% THEN s t%=0÷e21020 head%=2*i%+5÷e21030 =st%÷e21 040 :÷e21050 DEF FNF#get(rec%):LOCAL r%÷ j21060 r%=rec%MOD Rmax%÷e21070 IF VALLEF T$(R$(r%),4)<>rec% THEN PTR£handle%=head %+(rec%MOD1000)*rlen%÷e:INPUT£handle%,R$ (r%)÷e21080 IF VALLEFT$(R$(r%),4)<>tic% THEN STOP:REM File Error÷e21090 =r%÷e|c
P725 CEEFA( 725 Mon 10 Nov 21:12/01 |B2201202|b16FWrite|j24BBBC332k|l43000|p ÷e20780REM ***************************** ÷e20790RJM * * ÷e20800RJM * Random File Write * ÷e20810RJM * (c) 1986 J. Meets * ÷e20820REM * Prestel Mailbox 707327277 * ÷e20830RJM * * ÷e20840REM ***************************** ÷e20850:÷e20860REM Write a string to a f ield in a record÷e20870DEF FNwrite(tic%, f%,F$):LOCAL st%,rlen*,head%,r%÷e40880IF rec%<1000 OR rec%>last% OR rw%<>2 OR f% =1 THEN=FALSE÷e20890st%=FNstart(f%):IF s t%=0 THEN=FALSE÷e20900r%=FNF#get(rec%)÷e 20910F$=LEFT$(F$+STRING$(lin%(f%)," "),l en*(f%))÷e20920R$(r%)=LEFT$(R$(r%),st%-1 )+F$+RIGHT$(R$(r%),LENT$(r%)-(st%+len%(f %)-1))÷e20930=FNsv(r%)÷e20940:÷e20950REM Get the field start, also calc the rico rd length and file offset÷e20960DEF FNst art(f%):LOCAL i%,st%÷e20970rlin%=1:i%=0: REPEAT÷e20980IF i%<f% THEN st%=st%+len%( i%)÷e40990rlen%=rlin*+len%(i%)÷e2100|c
P725 CEEFAX 725 Mon 10 Nov 21:01/58 |B2202202|a16FWrite|j24BBBC332k|l43355|p 0i%=i%+1:UNTIL lin%(i%)=0÷e21010IF f%>=i % THEN st%=0÷e21020head%=2*i%+5÷e21030=s t%÷e21040:÷e21050DEF FNF#get(tic%):LOCAL r%÷e21060r%=rec%MOD Rmax%÷e21070IF VALL EFT$(R$(r%),4)<>rec% THEN PTR£handle%=hj ad%+(rec%MOD1000)*rlen%:INPUT£handle%,R$ (r%)÷e21080IF VALLEFT$(R$(r%),4)<>rec% T HEN STOP:REM File Error÷e21090=r%÷e21095 :÷e21100DEF FNsv(r%):LOCAL rec%÷e21110re c%=VALLEFT$(R$(r%),4)÷e21120IF rw%<>2 OR LENT$(r%)<>rlen*-2 THEN=FALSE÷e21130PTR £handle%=head%+(rec%MOD1000)*rlen%:PRINT £handle%,R$(r%)÷e21140=TRUE÷e21150:÷e|c