100 rem ******************************* 110 rem *gce o level computer studies* 120 rem * * 130 rem * database by neil kendall * 140 rem * written in 1987 * 143 rem * * 145 rem *retyped by cole in july 2004* 150 rem ******************************* 160 rem 165 fi=0:rem no file selected 170 poke 53280,0:poke 53281,11:rem set screen colours 180 print"{black}":rem set text colour black 190 print"{clear}":rem clear screen 195 open 15,8,15,"initialise":close 15:rem initialise drive 200 rem ********************* 210 rem * display main menu * 220 rem ********************* 221 if fi=o then print"no file selected." 222 if fi=1 then print"number of records entered:";ru 223 if fi=1 then print"{down}file selected:";s$ 230 print"{down*3} (1) create a new file." 240 print"{down} (2) search file." 250 print"{down} (3) ammend a record." 270 print"{down} (5) add next record." 280 print"{down} (6) select a file." 290 rem 300 get a$:if a$="" then 300 310 if a$="1" then goto 1000 320 if a$="2" then gosub 2000 330 if a$="3" then gosub 3000 340 if a$="4" then gosub 4000 350 if a$="5" then gosub 5000 355 if a$="6" then gosub 6000 360 goto 190 1000 rem ********************* 1010 rem * create a new file * 1020 rem ********************* 1025 clr: rem clear all variables 1030 print"{clear}":rem clear screen 1040 print"create a new file." 1050 for a=1 to 500:next a:rem slight pause 1060 print"enter number of fields." 1070 print"(maximum=10){down}" 1080 input f 1090 if f<1 or f>10 then print"illegal input.":goto 1060: rem validate input 1100 print"{clear}":rem clear screen 1110 print"fields=";f 1120 print"{down*2}" 1130 dim f$(f,10):rem setup string for fields names 1140 rem get fields names 1150 print"{down*2}" 1160 for a=1 to f:rem start loop 1170 print"name of field ";a;"?" 1180 input f$(a,10) 1185 rem validate input 1190 if len(f$(a,10))>10 then print"maximum of 10 chars please.":goto 1170 1200 next a 1205 gosub11000:rem make fields 10 chars 1210 print"{clear}" 1220 rem display names to see if correct 1230 print"{down*2}" 1240 for a=1 to f 1250 print"{down}field ";a;"= ";f$(a,10) 1260 next a 1270 print"{down*2}is this correct ?" 1280 get a$:if a$="" then 1280 1290 if a$="n" then print"{clear}":goto 1140 1300 if a$<>"y" then goto 1280 1310 print"{clear}" 1320 print"{down*2}insert a formatted disk into the" 1330 print"{down}disk drive then press space." 1340 get a$:if a$<>" "then 1340 1350 print"{clear}" 1360 print"{down*2}input then name of the file." 1370 print"{down}" 1380 input n$ 1390 if len(n$)>10 then print"maximum of 10 chars.":goto 1360 1400 print"{clear}" 1410 print"{down*2}creating file..." 1420 rl=(f*20):rem record length 1430 open 15,8,15,"s:"+n$:rem erase any existing file 1440 close 15 1450 open 2,8,2,n$+",l,"+chr$(rl) 1457 close 2 1470 rem now save field names as a sequential file 1475 ru=0:rem no records used 1480 open 2,8,2,"@0:fn"+n$+",s,w" 1481 print#2,f:rem no. of fields 1482 print#2,ru:rem no.records used 1490 for a=1 to f 1500 print#2,f$(a,10) 1510 next a 1520 close 2 1530 print"{clear}" 1540 print"{down*2}file created." 1550 for a=1 to 500:next a 1560 goto 190 2000 rem ***************** 2010 rem * search a file * 2020 rem ***************** 2030 if fi=0 then print"{clear}{down}no files selected.":for a=1 to 500:next a:return 2040 if ru=0 then print"{clear}{down}no records entered.": for a=1 to 500:next a:return 2050 print"{clear}{down}field search." 2060 print"{down*2}" 2070 for a=1 to f 2080 print"{down}field";a;":";f$(a,10) 2090 next a 2100 print"{down*2}please select field you wish to search." 2110 input sf 2120 if sf<1 or sf>f then print"between 1 &";f;"please":goto 2100 2130 print"{clear}{down}search field number";sf 2140 print"{down*3}" 2150 print"enter string to be searched for within" 2160 print"field number";sf 2170 print"{down*2}" 2180 input ss$ 2190 open 2,8,2,s$ 2200 open 1,8,15 2201 z=0 2210 for a=1 to ru 2220 r2=int(a/256):r1=a-r2*256 2230 print#1,"p"chr$(2+96)chr$(r1)chr$(r2)chr$(1) 2240 for b=1 to sf 2250 input#2,c$ 2260 next b 2270 if c$=ss$ then z=z+1:goto 2500 2280 next a 2290 close 2:close 1 2300 if z=0 then print"{clear}{down}no records found." 2305 if z=1 then print"{clear}{down}1 record found." 2307 if z>1 then print"{clear}{down}";z;"records found." 2310 for a=1 to 700:next a 2320 return 2500 print"{clear}" 2510 print"{down}record number";a 2520 print"{down*2}" 2530 print#1,"p"chr$(2+96)chr$(r1)chr$(r2)chr$(1) 2540 for t=1 to f 2550 input#2,t$ 2560 print"{down}";f$(t,10);":";t$ 2570 next t 2580 print"{down*2}" 2590 print"(1) continue searching." 2600 print"(2) main menu." 2610 get a$:if a$=""then 2610 2620 if a$="1" then goto 2280 2630 if a$="2" then close 2:close 1:return 2640 goto 2610 3000 rem ******************* 3010 rem * ammend a record * 3020 rem ******************* 3030 print"{clear}" 3031 if fi=0 then print"no file selected.":for a=1 to 500:next a:return 3032 if ru=0 then print"no records selected.":for a=1 to 500:next a:return 3040 print"{down}ammend a record." 3050 print"{down*2}which record do you wish to ammend ?" 3060 input rn 3070 if rn<1 or rn>ru then print"between 1 &"ru;"please.":goto 3050 3080 r2=int(rn/256):r1=rn-r2*256 3085 gosub 13000:rem see if record is present 3090 open 2,8,2,s$:close 2:gosub 10000 3091 if r=62 then print"{clear}{down}wrong disk.":for i=1 to 500:next a:return 3092 open 1,8,15:open 2,8,2,s$ 3100 print#1,"p"chr$(2+96)chr$(r1)chr$(r2)chr$(1) 3110 print"{clear}{down*2}record number";rn 3120 print"{down*2}" 3130 for a=1 to f 3140 ne$="" 3160 print f$(a,10);":"; 3170 input#2,ne$ 3180 print ne$ 3190 next a 3195 close 2:close 1 3200 print"{down*2}ok ? (y/n)" 3210 get a$:if a$="" then 3210 3220 if a$="y" then return 3230 if a$="n" then 3300 3240 goto 3210 3300 p=1:gosub 5110:p=0:print"{clear}{down}record";rn;"ammended":fora=1to500:nexta:return 4000 rem **************** 4010 rem * view records * 4020 rem **************** 4030 print"{clear}" 4031 if fi=0 then print"no file selected.":for a=1 to 500:next a:return 4032 if ru=0 then print"no file entered.":for a=1 to 500:next a:return 4040 print"view records." 4050 print"{down*2}which record do you wish to view ?" 4060 input rn 4070 if rn<1 or rn>ru then print"between 1 &";ru;"please.":goto 4050 4075 if rn=501 then print"{clear}{down*2}no more records.":for a=1 to 500:next a:return 4076 if rn>ru then print"{clear}{down*2}no more records entered.":fora=1to 500:nexta:return 4080 print"{clear}" 4090 print"record number";rn 4100 print"{down*3}" 4110 r2=int(rn/256):r1=rn-r2*256 4120 open 2,8,2,s$ 4130 gosub 10000:if r=62 then print"{clear}wrong disk .":for a=1 to 500:next a:return 4135 close 2 4145 open 2,8,2,s$ 4146 open 1,8,15 4147 print#1,"p"chr$(2+96)chr$(r1)chr$(r2)chr$(1) 4151 for a=1 to f 4152 re$="" 4160 print"{down}";f$(a,10);":"; 4170 input#2,re$ 4180 print re$ 4190 next a 4191 close 2 4192 close 1 4210 print"{down*2}" 4220 print"(1) next record." 4230 print"(2) main menu." 4240 get a$:if a$="" then 4240 4250 if a$="1" then rn=rn+1:goto 4075 4260 if a$="2" then return 4270 goto 4240 5000 rem ******************* 5010 rem * add next record * 5020 rem ******************* 5030 print"{clear}" 5031 iffi=0 then print"no file selected.":for a=1 to 500:next a:return 5040 print"add next record." 5045 print"{down}record number:";ru+1 5050 open 2,8,2,s$ 5060 gosub 10000 5065 close 2 5070 if r=62 then print"{clear}wrong disk in drive.":fora=1to1000:nexta:close2:return 5080 if ru=500 then print"{clear}no records left.":for a=1 to 1000:next a:return 5090 ru=ru+1:rn=ru 5110 r2=int(rn/256):r1=rn-r2*256 5115 re$="" 5116 print"{down}" 5127 for a=1 to f 5130 print f$(a,10); 5140 input t$(a,20) 5150 if len(t$(a,20))<1orlen(t$(a,20))>19thenprint"1-19 chars please.":goto5130 5155 t$(a,20)=t$(a,20)+chr$(13) 5170 re$=re$+t$(a,20) 5180 next a 5181 open 2,8,2,s$:open 15,8,15 5185 print#15,"p"chr$(2+96)chr$(r1)chr$(r2)chr$(1) 5186 print#2,re$ 5187 close2:close15 5188 gosub 5500 5190 print"{clear}" 5200 if p=1 then for a=1to 500:next a:return 5205 print"record";rn;"added." 5210 print"{down*2}(1) next record." 5220 print"{down}(2) main menu." 5230 get a$:if a$="" then 5230 5240 if a$="1" then print"{clear}":goto 5045 5250 if a$="2" then return 5260 goto 5230 5500 rem update records used 5510 open 2,8,2,"@0:fn"+s$+",s,w" 5520 print#2,f 5530 print#2,ru 5540 for a=1 to f 5550 print#2,f$(a,10) 5560 next a 5570 close 2 5580 return 6000 rem ***************** 6010 rem * select a file * 6020 rem ***************** 6021 clr 6030 print"{clear}" 6040 print"{down}input name of file you wish to select." 6050 print"{down}" 6060 input s$ 6070 print"{clear}" 6080 print"{down*2}insert required disk into the disk" 6090 print"drive and press space." 6100 get a$:if a$<>" " then 6100 6105 print"{clear}" 6110 open 2,8,2,s$ 6130 gosub 10000:rem read error channel 6140 if r=62orr=74thenprint"no file.":fora=1to1000:nexta:fi=0:close2:goto190 6150 rem error 62 = file not found 6160 close 2 6170 open 2,8,2,"fn"+s$ 6180 input#2,f:rem get no. of files 6181 input#2,ru:rem get no.records used 6190 for a=1 to f 6200 input#2,f$(a,10) 6210 next a 6215 close 2 6220 gosub11000:rem make fields 10 chars 6240 for a=1 to 500:next a 6245 dim t$(f,20) 6250 fi=1:goto 190 10000 rem ********************* 10010 rem * read error chanel * 10020 rem * return cod in r * 10030 rem ********************* 10040 open 15,8,15 10050 input#15,r 10060 close 15 10070 return 11000 rem ************************ 11010 rem * make fields 10 chars * 11020 rem ************************ 11030 for a=1 to f 11040 lp=10-len(f$(a,10)) 11045 np$="" 11050 for b=1 to lp 11060 np$=np$+" " 11070 next b 11080 np$=np$+f$(a,10) 11090 f$(a,10)=np$ 11100 next a 11110 return 13000 rem see if record is present 13001 open 1,8,15:open 2,8,2,s$ 13003 print#1,"p"chr$(96+2)chr$(r1)chr$(r2)chr$(1) 13010 gosub 10000:rem read error channel 13020 if r=50 then goto 13500:rem record not present 13026 close 1:close 2 13030 return 13500 print"{clear}" 13510 prin"{down*2}record";rn;"has not been entered" 13520 print"into the file." 13530 for a=1 to 1500:next a 13540 goto 190:rem goto main menu