10 REM A database that uses a record structure and a sequential file.
   20 SYS "GetStdHandle", -10 TO @hfile%(1)
   30 SYS "GetStdHandle", -11 TO @hfile%(2)
   40 SYS "SetConsoleMode", @hfile%(1), 0
   50 *INPUT 13
   60 *OUTPUT 14
   70 DIM details{name$, phone$, email$,response%(1,10)}
   80 DIM contact{(100)} = details{}
   90 DIM temp{(1)} = contact{(100)}
  100 counter = 0
  110 FOR d = 1 TO 100
  120   FOR c = 1 TO 10
  130     contact{(d)}.response%(1,c) = 0
  140   NEXT c
  150 NEXT d
  160 REPEAT
  170   PRINT
  180   PRINT"1.  Create a record."
  190   PRINT"2.  Save records to file."
  200   PRINT"3.  Delete a record."
  210   PRINT"4.  Sort records."
  220   PRINT"5.  List records."
  230   PRINT"6.  Search for a record."
  240   PRINT"7.  Input a response."
  250   PRINT"8.  Initialise the types of responses."
  260   PRINT"9.  List total number of different responses."
  270   PRINT"10. Load file."
  280   PRINT"11. Exit."
  290   INPUT"Choose... "choice
  300   PRINT
  310   IF choice = 1 THEN PROCcreate
  320   IF choice = 2 THEN PROCsave
  330   IF choice = 3 THEN PROCdelete
  340   IF choice = 4 THEN PROCsort
  350   IF choice = 5 THEN PROClist
  360   IF choice = 6 THEN PROCsearch
  370   IF choice = 7 THEN PROCresponse
  380   IF choice = 8 THEN PROCinitialise
  390   IF choice = 9 THEN PROClistresponse
  400   IF choice = 10 THEN PROCload
  410 UNTIL choice = 11
  420 IF choice = 11 THEN QUIT
  430 END
  440
  450 DEFPROCcreate
  460 counter = counter + 1
  470 INPUT"Name " contact{(counter)}.name$
  480 INPUT"Phone number ",contact{(counter)}.phone$
  490 INPUT"Email address ", contact{(counter)}.email$
  500 ENDPROC
  510
  520 DEFPROCsave
  530 phonenos=OPENOUT "Phonenos.txt"
  540 PRINT "File Name Phonenos.txt Opened as Channel ";phonenos
  550 PRINT
  560 FOR j= 1 TO counter
  570   PRINT#phonenos,contact{(j)}.name$,contact{(j)}.phone$,contact{(j)}.email$
  580   FOR f = 1 TO 10
  590     PRINT#phonenos, contact{(j)}.response%(1,f)
  600   NEXT f
  610  
  620 NEXT j
  630 CLOSE#phonenos
  640 PRINT "Data saved."
  650 ENDPROC
  660
  670 DEFPROCdelete
  680 INPUT"Enter the number of a record you wish to delete "delete
  690 FOR loop = delete TO counter
  700   contact{(loop)}.name$ =  contact{(loop+1)}.name$
  710   contact{(loop)}.phone$ = contact{(loop+1)}.phone$
  720   contact{(loop)}.email$ = contact{(loop+1)}.email$
  730 NEXT loop
  740 counter = counter -1
  750 ENDPROC
  760
  770 DEFPROCsort
  780 REPEAT
  790   noswaps = TRUE
  800   FOR t = 1 TO counter - 1
  810     IF contact{(t)}.name$ > contact{(t+1)}.name$ THEN PROCswap
  820   NEXT t
  830 UNTIL noswaps = TRUE
  840 ENDPROC
  850
  860 DEFPROClist
  870 CLS
  880 IF counter > 0 THEN
  890   FOR g = 1 TO counter
  900     PRINT
  910     PRINT"Record number ";g
  920     PRINT contact{(g)}.name$
  930     PRINT contact{(g)}.phone$
  940     PRINT contact{(g)}.email$
  950     PRINT
  960   NEXT g
  970 ENDIF
  980 ENDPROC
  990
 1000 DEFPROCswap
 1010 temp{(1)} = contact{(t)}
 1020 contact{(t)}= contact{(t+1)}
 1030 contact{(t+1)} = temp{(1)}
 1040 noswaps = FALSE
 1050 ENDPROC
 1060
 1070 DEFPROCsearch
 1080 INPUT"Enter the name of a record to look for ";person$
 1090 FOR i = 1 TO counter
 1100   IF contact{(i)}.name$ = person$ THEN
 1110     PRINT
 1120     PRINT contact{(i)}.name$
 1130     PRINT contact{(i)}.phone$
 1140     PRINT contact{(i)}.email$
 1150     PRINT"Number of replys using the following channels:-"
 1160     PRINT"Phone ";contact{(i)}.response%(1,1)
 1170     PRINT"Email ";contact{(i)}.response%(1,2)
 1180     PRINT"Letter ";contact{(i)}.response%(1,3)
 1190     PRINT"Flyer ";contact{(i)}.response%(1,4)
 1200     PRINT"Word of mouth ";contact{(i)}.response%(1,5)
 1210     PRINT"Circulars ";contact{(i)}.response%(1,6)
 1220     PRINT"Visit ";contact{(i)}.response%(1,7)
 1230     PRINT"Advertising ";contact{(i)}.response%(1,8)
 1240     PRINT"Website ";contact{(i)}.response%(1,9)
 1250     PRINT"Publication ";contact{(i)}.response%(1,10)
 1260     PRINT
 1270   ENDIF
 1280 NEXT
 1290 ENDPROC
 1300
 1310 DEFPROCresponse
 1320 INPUT"Do you wish to input a response (Y) or (y), or(N) or (n) ",yestoresponse$
 1330 IF yestoresponse$ = "Y" OR yestoresponse$ = "y" THEN
 1340   INPUT"Enter the number of a record to look for ";i
 1350   PRINT
 1360   PRINT contact{(i)}.name$
 1370   PRINT contact{(i)}.phone$
 1380   PRINT contact{(i)}.email$
 1390  
 1400   PRINT"Which contact method did you receive a response$ from, (p)hone, (e)mail,"
 1410   PRINT"(l)etter, (f)lyer, (w)ord of mouth, (c)irculars, (v)isit, (a)dvertising,"
 1420   PRINT"(we)bsite, (pu)ublication"
 1430   INPUT method$
 1440   IF method$ = "p" THEN contact{(i)}.response%(1,1) = contact{(i)}.response%(1,1) + 1
 1450   IF method$ = "e" THEN contact{(i)}.response%(1,2) = contact{(i)}.response%(1,2) + 1
 1460   IF method$ = "l" THEN contact{(i)}.response%(1,3) = contact{(i)}.response%(1,3) + 1
 1470   IF method$ = "f" THEN contact{(i)}.response%(1,4) = contact{(i)}.response%(1,4) + 1
 1480   IF method$ = "w" THEN contact{(i)}.response%(1,5) = contact{(i)}.response%(1,5) + 1
 1490   IF method$ = "c" THEN contact{(i)}.response%(1,6) = contact{(i)}.response%(1,6) + 1
 1500   IF method$ = "v" THEN contact{(i)}.response%(1,7) = contact{(i)}.response%(1,7) + 1
 1510   IF method$ = "a" THEN contact{(i)}.response%(1,8) = contact{(i)}.response%(1,8) + 1
 1520   IF method$ = "we" THEN contact{(i)}.response%(1,9) = contact{(i)}.response%(1,9) + 1
 1530   IF method$ = "pu" THEN contact{(i)}.response%(1,10) = contact{(i)}.response%(1,10) + 1
 1540 ENDIF
 1550 ENDPROC
 1560
 1570 DEFPROClistresponse
 1580 one% = 0
 1590 two% = 0
 1600 three% = 0
 1610 four% = 0
 1620 five% = 0
 1630 six% = 0
 1640 eight% = 0
 1650 nine% = 0
 1660 ten% = 0
 1670 FOR a = 1 TO counter
 1680   one% = one% + contact{(a)}.response%(1,1)
 1690   two% = two% + contact{(a)}.response%(1,2)
 1700   three% = three% + contact{(a)}.response%(1,3)
 1710   four% = four% + contact{(a)}.response%(1,4)
 1720   five% = five% + contact{(a)}.response%(1,5)
 1730   six% = six% + contact{(a)}.response%(1,6)
 1740   seven% = seven% + contact{(a)}.response%(1,7)
 1750   eight% = eight% + contact{(a)}.response%(1,8)
 1760   nine% = nine% + contact{(a)}.response%(1,9)
 1770   ten% = ten% + contact{(a)}.response%(1,10)
 1780 NEXT
 1790 PRINT"Phone ";one%
 1800 PRINT"Email ";two%
 1810 PRINT"Letter ";three%
 1820 PRINT"Flyer ";four%
 1830 PRINT"Word of mouth ";five%
 1840 PRINT"Circular ";six%
 1850 PRINT"Visit ";seven%
 1860 PRINT"Advertising ";eight%
 1870 PRINT"Website ";nine%
 1880 PRINT"Publication ";ten%
 1890 ENDPROC
 1900
 1910 DEFPROCload
 1920 counter = 0
 1930 IF OPENIN "Phonenos.txt" THEN
 1940  
 1950   phonenos=OPENIN "Phonenos.txt"
 1960   PRINT "File Name Phonenos.txt Opened as Channel ";phonenos
 1970   PRINT
 1980   REPEAT
 1990     counter = counter + 1
 2000     INPUT#phonenos,contact{(counter)}.name$,contact{(counter)}.phone$,contact{(counter)}.email$
 2010     FOR e = 1 TO 10
 2020       INPUT#phonenos, contact{(counter)}.response%(1,e)
 2030     NEXT e
 2040   UNTIL EOF#phonenos
 2050   CLOSE#phonenos
 2060 ELSE
 2070   PRINT"No file to open."
 2080 ENDIF
 2090 ENDPROC
 2100
 2110 DEFPROCinitialise
 2120 FOR a = 1 TO counter
 2130   contact{(a)}.response%(1,1)  = 0
 2140   contact{(a)}.response%(1,2)  =0
 2150   contact{(a)}.response%(1,3)  =0
 2160   contact{(a)}.response%(1,4)  =0
 2170   contact{(a)}.response%(1,5)  =0
 2180   contact{(a)}.response%(1,6) =0
 2190   contact{(a)}.response%(1,7) =0
 2200   contact{(a)}.response%(1,8) =0
 2210   contact{(a)}.response%(1,9) =0
 2220   contact{(a)}.response%(1,10) =0
 2230 NEXT
 2240 ENDPROC

Comments