P726 CEEFAX 726 Mon 10 Nov 21:22/41 |B2201206}b17FWriteT|j24BBBC332k|l43000| p÷e DISK NUMBER : DISK CATEGORY : DISC÷e FILJNAME : F.WRITE-T÷e ÷e ÷ j MACHINE BBC B/B+/Master÷e BASIC 1 or 2÷e Any OS, Any DOS÷e P JRJPHERALS Disc Drives ÷e TAPE COMPATIBILITY No÷ e ÷e ÷e LINENUMBER 20780-21150÷e NAME FNwrite(rec%,f%,F$)÷e ÷e ÷e AUTHOR J. Meets÷e REFERENCE Random Access Routines÷e ÷e CLASSIFJCATJON Disc Rbndom Access÷e DESCRJPTJON Writes text into a spec ified jield÷e÷a÷a in a specified record.÷e ÷e PARAMET IRS REQUIRED rec% 4 digit recor|c
P726 CEEFAX 726 Mon 10 Nov 21:13/07 |B2202206}b17FWriteT|j24BBBC332k|l43352| pd number.÷e f% field number.÷e F$ field contents.÷e÷e PARAMETERS RETU5NED TRUE if w rite was successful.÷e FALSE if it failed.÷e ÷e GLOBAL VARIABLES Rmax% Max number of records held÷e in memory.÷e rw% read/write flag.÷e R$(Rmax *) Array for records in memory.÷e len*(20) Ar ray for lengths of fields.÷e handle% Handle for opened file.÷i last% Last valid record number.÷e÷e ÷e MODE DEPENDENCE None÷e ÷e OTHER MO DULES CALLED Uses FNstart, FNF# get, FNsv÷e OTHER MODULES RELATE|c
P726 CEEFAX 726 Mon 10 Nov 21:11/32 |B2203206|b17FWriteT|j24BBBC332k|l436AA| pD include F.INIT, F.WRITE÷e ÷e COMMENTS Th is procedure checks for possible ÷e error cond itions, then uses FVstart to÷efind the o ffset to the start of the required field . FNF#get is used to÷eget the record in to memory. The string F$ is adjusted in length and put in÷ethe correct part of t hj record string, which is then written to disc.÷eFNstart runs through the len% array to calculate the start of the feel d.÷eIt also calculates the record length rlen% and file offset head%, and÷echjck s that the field requested exists. ÷iFN F#get maintains several records in memo ry as text strings in R$(Rmax%).÷eIf the required record is not in memory then t he file pointer is÷ecalculated and the r ecord read in. A final check is made th at the correct÷erecord has been retrieve d.÷eFNsv performs additional checks |c
P726 CEEFAX 726 Mon 10 Nov 21:18/52 |B2204206}b17FWriteT|i24BBBC332k|l43A07| pand then alters the disc file. This÷ef unction can bj used separately, "ut call FNstart first to set rlen% and÷ehjad%.÷ j ÷e TYPICAL CALL AND LISTING÷e÷e 10 REM Random File Routines÷e 20 :÷e 30 RE M Initialisj÷e 40 PROCF#Init("test",2) ÷e 50 :÷e 90 REM Write TEST to field 2, rec 1004÷e 100 PRINT FNwrite(1004,2 ,"TEST")÷e 110 :÷e 120 END÷e Q30 :÷e2 0780 REM *****************************÷e 20790 REM * *÷ j20800 REM * Random File Write * ÷e40810 REM * (c) 198v J. Meets *÷e40820 REM * Prestel Mailbox 707327277 *÷e20830 REM * *÷e20840 REM ************************* ****÷e40850 :÷e20860 REM Write a string to a field in a record÷e20870 DEF FVwrit e(rec%,f%,F$):LOCAL st%,rlin*,head%,r%÷e 20880 IF rec%<1000 OR rec%>last% OR rw%< >2 OR f%=1 THEN=FALSE÷e20890 st%=FMs|c
P726 CEEFAX 726 Mon 10 Nov 21:14/16 |B2205206|aQ7FWriteT|i24BBBC332k|l43D57| ptart(e%):IF st%=0 THEN=FALSE÷e20900 r%= FNF#get(rec%)÷e20910 F$=LEFT$(F$+STRING$ (len%(f%)," "),len%(f%))÷i20920 R$(r%)=L EFT$(R$(r%),st%-1)+F$+RIGHT$(R$(r%),LENT $(r))-(st%+len*(f%)-1))÷e20930 =FNsv(r%) ÷e20940 :÷e20950 REM Get the field start , also calc the record length and file o ffset÷e20960 DEF FNstart(f%):LOCAL i%,st *÷e20970 rlen*=1:i%=0:REPEAT÷e20980 IF i%<f% THEN st%=st%+len*(i%)÷e20990 rl en*=rlen*+len*(i%)÷e21000 i%=i%+1:UNTI L len*(i%I=0÷e41010 IF f%>=i% THEN st%=0 ÷e21020 head%=2*i%+5÷e21030 =st%÷e21040 :÷e21050 DEF FNF#get(rec%):LOCAL r%÷e210 60 r%=rec%MOD Rmax%÷e21070 IF VALLEFT$(R $(r%),4)<>rec% THEN PTR£handle%=head%+(r ec%MOD1000)*rlen*:INPUT£handle%,R$(r%)÷e 21080 IF VALLEFT$(R$(r%),4)<>rec% THEN S TOP:REM File Error÷e21090 =r%÷e21095 :÷e 21100 DEF FNsv(r%):LOCAL rec%÷e21110 rec %=VALLEFT$(R$(r%),4)÷e21120 IF rw%<>2 OR LENT$(r%)<>rlen%-2 THEN=FALSE÷e2113|c
P726 CEEFAX 726 Mon 10 Nov 21:19/31 |B2206206}b17FWriteT|j24BBBC332k|l440A9} p0 PTR£handle%=hjadJ+(rec%MOD1000)*rlen% :PRINT£handle%,R$(r%)÷e21140 =TRUE÷e2115 0 :÷e|c
P726 CEEFA( 726 Mon 10 Nov 21:17/54 |B2201202|a15FRead|i24BBBC332k|l43000|p÷ e20640REM *****************************÷ e206u0RJZ * *÷ j40vv0RJM * Random File Read *÷ j20670RJM * (c) 1986 J. Meets *÷ e20v80RJM * Prestel Mailbox 707327277 *÷ j40690RJM * *÷ j40700REM *****************************÷ e40710:÷e20720REM Read Record Mum, Field ÷e20730DEF FNread(rec%,f%):LOCAL st%,rle n*,head%÷e20740IF rec%<1000 OR rec%>last J OR rw%<1 THEN="ERROR"÷i20750st%=FVstar t(f%):IF st%=0 THEN="ERROR"÷e20760=MID$( R$(FNF#get(rec%)),st%,len%(f%))÷e20770:÷ e40950REM Get the field start, also calc the record length and file offset÷e2096 0DEF FNstart(f%):LOCAL i%,st%÷e20970rlen I=1:i%=0:REPEAT÷e20980IF i%<f% THEN st%= st%+len%(i%)÷e20990rlen*=rlen*+len%(i%)÷ e21000i%=i%+1:UNTIL len*(i%)=0÷e21010IF f%>=i% THEN st%=0÷e21020head%=2*i%+5÷e21 030=st%÷e21040:÷e21050DEF FNF#get(rec%): LOCAL r%÷e21060r%=rec%MOD Rmax%÷e210|c
P726 CEJFAX 726 Mon 10 Nov 21:22/22 |B2202202|a1uFRjad|j24BBBC332k|l43352|p7 0IF VALLEFT$(R$(r%),4)<>rec% THEN PTR£ha ndle%=head*+(rec%MOD1000)*rlen*:INPUT£ha ndle%,R$(r%)÷e21080IF VALLEFT$(R$(r%),4) <>rec% THEN STOP:REM File Error÷e21090=r *÷e21095:÷e|c