home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1993 May / 1993-05.d64 / database (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  4KB  |  182 lines

  1. 10 rem copyright 1993 - compute publications intl ltd - all rights reserbed
  2. 20 poke53280,6:poke53281,6:print"[147]"
  3. 100 rem simple flat file data base
  4. 110 n9=50
  5. 120 dim a$(n9),b$(n9),c$(n9),d(n9)
  6. 130 s$="                 "
  7. 140 m9$="..janfebmaraprmayjunjulaugsepoctnovdec"
  8. 200 open 15,8,15
  9. 210 open 1,8,3,"0:mydata,s,r"
  10. 220 input#15,e,e$
  11. 230 if e=0 goto 300
  12. 240 close 1:close 15
  13. 250 print "i cannot find file 'mydata'"
  14. 260 input "continue";x$
  15. 270 if x$="y" or x$="yes" goto 400
  16. 280 end
  17. 300 n=n+1
  18. 310 input#1,a$(n),b$(n),c$(n),d(n)
  19. 320 if st=0 goto 300
  20. 330 close 1:close 15
  21. 340 print n;"records found on file."
  22. 350 if n+10>n9 then print "file almost full!"
  23. 400 if n>0 then print "show, ";
  24. 410 if n<n9 then print "add, ";
  25. 420 if n>0 then print "delete, change, ";
  26. 430 print "quit?"
  27. 440 input x$:x$=left$(x$,1)
  28. 450 if n=0 goto 490
  29. 460 if x$="s" goto 4000
  30. 470 if x$="d" goto 2000
  31. 480 if x$="c" goto 3000
  32. 490 if n=n9 goto 510
  33. 500 if x$="a" goto 1000
  34. 510 if x$<>"q" goto 400
  35. 520 rem quit .. but perhaps write file
  36. 530 if f9=0 or n=0 then end
  37. 540 print "ready to write file!"
  38. 550 print "press any key."
  39. 560 get x$,x$,x$
  40. 570 get x$:if x$="" goto 570
  41. 580 rem delete archive if present
  42. 590 open 15,8,15
  43. 600 print#15,"s0:mydata.old"
  44. 610 rem rename previous data file
  45. 620 print#15,"r0:mydata.old=0:mydata"
  46. 630 rem write new master file
  47. 640 open 1,8,3,"0:mydata,s,w"
  48. 650 input#15,e,e$
  49. 660 if e<>0 then print e;e$:close 1:close 15:end
  50. 670 for j=1 to n
  51. 680 print#1,a$(j)
  52. 690 print#1,b$(j)
  53. 700 print#1,c$(j)
  54. 710 print#1,d(j)
  55. 720 next j
  56. 730 input#15,e,e$,e1,e2
  57. 740 if e<>0 then print e;e$
  58. 750 close 1:close 15
  59. 760 end
  60. 1000 rem add a record
  61. 1010 input "last name";a$(n+1)
  62. 1020 input "first name";b$(n+1)
  63. 1030 v=n+1:gosub 8000 : rem get date
  64. 1040 input "high score";d(n+1)
  65. 1050 print
  66. 1060 print a$(n+1)
  67. 1070 print b$(n+1)
  68. 1080 print c$(n+1)
  69. 1090 print d(n+1)
  70. 1100 input "is the above ok";x$
  71. 1110 if x$="y" or x$="yes" goto 1140
  72. 1120 print ">>> record cancelled! <<<"
  73. 1130 goto 400
  74. 1140 n=n+1:f9=1
  75. 1150 print n;"records total."
  76. 1160 goto 400
  77. 2000 rem delete a record
  78. 2010 gosub 5000
  79. 2020 if x=0 goto 400
  80. 2030 print "ready to delete record:"
  81. 2040 print "  ";a$(x)
  82. 2050 print "  ";b$(x)
  83. 2060 m=val(mid$(c$(x),5,2))
  84. 2065 print "  ";left$(c$(x),4);mid$(m9$,m*3,3);right$(c$(x),2)
  85. 2070 print "  ";d(x)
  86. 2080 input "ok to delete";x$
  87. 2090 if x$="y" or x$="yes" goto 2120
  88. 2100 print "record >>>not<<< deleted!"
  89. 2110 goto 400
  90. 2120 n=n-1
  91. 2130 if x>n goto 2220
  92. 2140 for j=x to n
  93. 2150 a$(j)=a$(j+1)
  94. 2160 b$(j)=b$(j+1)
  95. 2170 c$(j)=c$(j+1)
  96. 2180 d(j)=d(j+1)
  97. 2190 next j
  98. 2200 f9=1
  99. 2210 print ">>> record deleted! <<<"
  100. 2220 goto 400
  101. 3000 rem change a record
  102. 3010 gosub 5000
  103. 3020 if x=0 goto 400
  104. 3030 print "ready to change record:"
  105. 3040 print "1:";a$(x)
  106. 3050 print "2:";b$(x)
  107. 3060 m=val(mid$(c$(x),5,2))
  108. 3065 print "3:";left$(c$(x),4);mid$(m9$,m*3,3);right$(c$(x),2)
  109. 3070 print "4:";d(x)
  110. 3080 input "change which field (0=none)";j
  111. 3090 j=int(j):if j<1 or j>4 then j=0
  112. 3100 on j goto 3120,3140,3160,3180
  113. 3110 goto 400
  114. 3120 input "last name";a$(x)
  115. 3130 f9=1:goto 3040
  116. 3140 input "first name";b$(x)
  117. 3150 f9=1:goto 3040
  118. 3160 v=x:gosub 8000 : rem get date
  119. 3170 f9=1:goto 3040
  120. 3180 input "high score";d(x)
  121. 3190 f9=1:goto 3040
  122. 4000 rem show - display or print
  123. 4010 input "screen or printer";x$
  124. 4020 x$=left$(x$,1)
  125. 4030 if x$="p" goto 4190
  126. 4040 if x$<>"s" goto 4010
  127. 4050 j=1
  128. 4060 k=j+20:if k=n then k=n+1
  129. 4070 print left$(a$(j)+s$,13);
  130. 4080 print left$(b$(j)+s$,10);
  131. 4090 m=val(mid$(c$(j),5,2))
  132. 4100 print left$(c$(j),4);mid$(m9$,m*3,3);right$(c$(j),2);
  133. 4110 print right$(s$+str$(d(j)),7)
  134. 4120 j=j+1:if j<>k goto 4170
  135. 4130 print "  >> more - press any key <<";chr$(145)
  136. 4140 get x$,x$,x$,x$
  137. 4150 get x$:if x$="" goto 4150
  138. 4160 goto 4060
  139. 4170 if j<=n goto 4070
  140. 4180 goto 400
  141. 4190 rem send to printer
  142. 4200 open 4,4
  143. 4210 for j=1 to n
  144. 4220 print#4,left$(a$(j)+s$,20);
  145. 4230 print#4,left$(b$(j)+s$,15);
  146. 4240 m=val(mid$(c$(j),5,2))
  147. 4250 print#4,left$(c$(j),4);mid$(m9$,m*3,3);right$(c$(j),2);
  148. 4260 print#4,right$(s$+str$(d(j)),10)
  149. 4270 next j
  150. 4280 close 4
  151. 4290 goto 400
  152. 5000 print "select which record:"
  153. 5010 j=1
  154. 5020 k=j+20:if k>n then k=n
  155. 5030 for s=j to k
  156. 5040 print right$(s$+str$(s),3);": ";left$(a$(s)+s$,12);
  157. 5050 print left$(b$(s)+s$,6);
  158. 5060 print left$(c$(s)+s$,8);
  159. 5070 print right$(s$+str$(d(s)),7)
  160. 5080 next s
  161. 5090 print ">> select record number, or 0 ";
  162. 5100 if k<>n then print "for more <<"
  163. 5110 if k=n then print "to quit <<"
  164. 5120 input x
  165. 5130 x=int(x):if x>n then x=0
  166. 5140 j=k
  167. 5150 if x=0 and k<>n goto 5020
  168. 5160 return
  169. 8000 input "year";y
  170. 8010 if y<1900 or y>9999 goto 8000
  171. 8020 input "month";m$
  172. 8030 m=val(m$):if m>0 and m<13 goto 8050
  173. 8040 m$=left$(m$+s$,3)
  174. 8050 for j=1 to 12
  175. 8060 if m$=mid$(m9$,j*3,3) then m=j
  176. 8070 next j
  177. 8080 if m<1 or m>12 goto 8020
  178. 8090 input "day";d
  179. 8100 if d<1 or d>31 goto 8090
  180. 8110 c$(v)=right$(str$(y),4)+right$(str$(m+100),2)+right$(str$(d+100),2)
  181. 8120 return
  182.