home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug001.arc / PART7.IQS / PART7.INS
Text File  |  1979-12-31  |  11KB  |  218 lines

  1. .po0
  2.                                dBasσ I╔ PAR╘ 7
  3.  
  4.           Thσ firs⌠ prograφ everybod∙ write≤ i≤ thσ "Hell∩ Worldó program« Iµ ì
  5. you'vσ neve≥ writteε thi≤ onσ before¼ it'≤ ß simplσ prograφ t∩ writσ "hell∩ ì
  6. Worldó oε thσ screen« S∩ iε dBase:
  7.  
  8.                ERASE
  9.                ┐ 'Hell∩ World'
  10.                
  11.      Thσ ERAS┼ commanΣ clear≤ thσ screen¼ whilσ thσ ┐ symbo∞ print≤ thσ strinτ ì
  12. oε thσ screen« Whilσ thi≤ demonstrate≤ nonσ oµ thσ intricacie≤ oµ thσ dBasσ ì
  13. language¼ a⌠ leas⌠ i⌠ show≤ tha⌠ dBasσ ha≤ nonσ oµ thσ intricacie≤ requireΣ b∙ ì
  14. othe≥ languages« Iε PL/╔ fo≥ example¼ thσ abovσ prograφ is:
  15.  
  16.                world:
  17.                proπ options(main):
  18.                pu⌠ ski≡ lis⌠ (ascii(26),'Hell∩ World');
  19.                enΣ world;
  20.  
  21.      That'≤ onσ oµ thσ thing≤ dBasσ ha≤ goinτ fo≥ it╗ it'≤ relativel∙ eas∙ t∩ ì
  22. writσ shor⌠ program≤ iε it« Yo⌡ don'⌠ eveε havσ t∩ worr∙ abou⌠ linσ numbers!
  23. However¼ program≤ arσ morσ usefu∞ iµ the∙ arσ ablσ t∩ perforφ repetitivσ task≤ ì
  24. o≥ t∩ makσ decision≤ baseΣ upoε thσ value≤ oµ variables« dBasσ provide≤ ß ì
  25. numbe≥ oµ way≤ oµ doinτ this.
  26.  
  27.      Thσ D╧ WHIL┼ statement¼ coupleΣ witΦ ß matchinτ ENDDO¼ i≤ thσ maiε wa∙ oµ ì
  28. controllinτ ß loop« Fo≥ example¼ herσ i≤ thσ wa∙ t∩ writσ ß FOR..NEX╘ loop:
  29.  
  30.                STOR┼ ▒ T╧ control
  31.                D╧ WHIL┼ contro∞ ╝ 11
  32.                ¬ maiε bod∙ oµ loop
  33.                ┐ control
  34.                STOR┼ contro∞ ½ ▒ t∩ control
  35.                ENDDO
  36.  
  37.      Thi≤ wil∞ prin⌠ thσ number≤ froφ ▒ t∩ 1░ oε thσ screen« Sincσ dBasσ i≤ ß ì
  38. databasσ manipulatioε language¼ ß morσ commoε usσ oµ thσ D╧ WHIL┼ statemen⌠ i≤ ì
  39. t∩ proces≤ ß databasσ filσ froφ beginninτ t∩ end« Likσ mos⌠ languages¼ dBasσ ì
  40. ha≤ ß functioε calleΣ EOF¼ whicΦ return≤ truσ wheε thσ systeφ read≤ thσ endif-ì
  41. filσ marker« S∩ t∩ proces≤ ß databasσ file¼ thσ followinτ dBasσ fragmen⌠ wil∞ ì
  42. d∩ thσ job:
  43.  
  44.                G╧ TOP
  45.                D╧ WHIL┼ .NOT« EOF
  46.                ¬ maiε bod∙ oµ loop
  47.                SKIP
  48.                ENDDO
  49.  
  50.      Here¼ thσ SKI╨ instructioε move≥ thσ filσ pointe≥ oε t∩ thσ nex⌠ record« ì
  51. Oncσ thσ fina∞ recorΣ ha≤ beeε processed¼ thσ SKI╨ instructioε wil∞ attemp⌠ t∩ ì
  52. movσ thσ filσ pointe≥ on¼ bu⌠ insteaΣ i⌠ wil∞ bum≡ int∩ thσ end-of-filσ ì
  53. marker« A⌠ thσ to≡ oµ thσ loop¼ thσ WHIL┼ conditioε wil∞ no≈ evaluatσ t∩ ì
  54. false¼ anΣ s∩ thσ bod∙ oµ thσ loo≡ wil∞ no⌠ bσ executed.
  55.  
  56. è     A≤ mentioneΣ above¼ i⌠ i≤ als∩ usefu∞ t∩ bσ ablσ t∩ ac⌠ iε differen⌠ way≤ ì
  57. unde≥ differen⌠ conditions« Iε dBase¼ a≤ iε man∙ othe≥ languages¼ thi≤ i≤ ì
  58. achieveΣ witΦ thσ I╞ ..« ENDI╞ statement« Iε somσ languages¼ thσ operatioε oµ ì
  59. I╞ statement≤ caε seeφ rathe≥ ambiguou≤ thank≤ t∩ thσ lacδ oµ clea≥ indicatioε ì
  60. wherσ thσ scopσ oµ aε I╞ ends¼ bu⌠ iε dBasσ thσ ENDI╞ make≤ i⌠ absolutel∙ ì
  61. clear« S∩ here'≤ aε examplσ oµ thσ I╞ construct:
  62.  
  63.                I╞ zo⌠ ╛ foobar
  64.                rangσ ╜ zo⌠ - foobar
  65.                ENDIF
  66.  
  67.      Noticσ tha⌠ thσ actioε t∩ bσ performeΣ iµ thσ conditioε i≤ truσ i≤ oε ß ì
  68. separatσ linσ froφ thσ I╞ statemen⌠ itself¼ ß differen⌠ stylσ froφ mos⌠ ì
  69. languages« Notσ tha⌠ yo⌡ arσ no⌠ restricteΣ t∩ jus⌠ onσ statemen⌠ followinτ ì
  70. thσ IF╗ yo⌡ caε havσ a≤ man∙ a≤ requireΣ - jus⌠ finisΦ eacΦ witΦ aε ENDIF.
  71.  
  72.      dBasσ als∩ allow≤ thσ usσ oµ aε ELS┼ clausσ s∩ tha⌠ onσ o≥ othe≥ oµ tw∩ ì
  73. alternative≤ i≤ executed:
  74.           
  75.                I╞ mgros≤ ╝ 0
  76.                ta° ╜ 0
  77.                ELSE
  78.                ta° ╜ mgros≤ ¬ 0.46
  79.                ENDIF
  80.  
  81.      Whilσ thσ I╞ ..« ELS┼ ..« ENDI╞ construc⌠ allow≤ thσ selectioε oµ onσ oµ ì
  82. tw∩ course≤ oµ action¼ ß frequen⌠ occurrencσ i≤ thσ requiremen⌠ t∩ selec⌠ onσ ì
  83. oµ man∙ alternatives« Thi≤ i≤ donσ b∙ thσ D╧ CAS┼ statement¼ whicΦ take≤ thσ ì
  84. genera∞ form:
  85.  
  86.                D╧ CASE
  87.                CAS┼ statement
  88.                statements
  89.                CAS┼ expression2
  90.                statements
  91.                CAS┼ expression3
  92.                statements
  93.                OTHERWISE
  94.                statements
  95.                ENDCAS┼     
  96.  
  97.      Thi≤ allow≤ thσ programme≥ t∩ handlσ an∙ numbe≥ oµ separatσ cases¼ plu≤ ß ì
  98. fina∞ se⌠ oµ statement≤ t∩ handlσ thσ situatioε wheε nonσ oµ thσ case≤ i≤ ì
  99. true.
  100.  
  101.      Thσ majo≥ usσ oµ thi≤ expressioε i≤ Θ ε menus¼ wherσ thσ use≥ ha≤ t∩ ì
  102. selec⌠ onσ oµ severa∞ alternatives« Here'≤ aε example:
  103.  
  104.                ERASE
  105.                D╧ WHIL┼ t
  106.                └ 5,1▓ SA┘ 'AdΣ Names'
  107.                └ 6,1▓ SA┘ 'Deletσ Names'
  108.                └ 7,1▓ SA┘ 'Quit'
  109.                └ 21,1▓ SA┘ 'Choice'
  110.                SE╘ CONSOL┼ OF╞                                       cont...è               WAI╘ T╧ mchoice
  111.                SE╘ CONSOL┼ ON
  112.                mchoicσ ╜ !(mchoice)
  113.                D╧ CASE
  114.                CAS┼ mchoicσ ╜ 'Aº D╧ addnam
  115.                CAS┼ mchoicσ ╜ 'Bº D╧ delnam
  116.                CAS┼ mchoicσ ╜ 'Qº ERASE
  117.                CANCEL
  118.                OTHERWISE
  119.                ┐ CHR(7)
  120.                ENDCASE
  121.                ENDDO
  122.  
  123.      Thi≤ examplσ show≤ ß fe≈ feature≤ oµ dBase« First¼ wσ havσ no⌠ previousl∙ ì
  124. seeε thσ ERAS┼ command╗ i⌠ simpl∙ clear≤ thσ screeε (thinδ oµ CL╙ iε TRS-8░ o≥ ì
  125. MICROWORL─ BASIC)« Nex⌠ thσ D╧ WHIL┼ t║ iε thi≤ case¼ ⌠ i≤ no⌠ ß variablσ - ì
  126. insteaΣ i⌠ i≤ thσ logica∞ constan⌠ true« Thσ resul⌠ oµ thi≤ i≤ tha⌠ truσ i≤ ì
  127. alway≤ true¼ s∩ thσ loo≡ alway≤ executes« Thσ onl∙ wa∙ ou⌠ i≤ t∩ selec⌠ "Q".
  128.  
  129.      Nex⌠ there'≤ thσ └ commands¼ whicΦ positioε thσ curso≥ oε thσ screeε ì
  130. beforσ output¼ anΣ thσ SA┘ command≤ whicΦ actuall∙ perforφ thσ output« Thσ ì
  131. dBasσ screeε extend≤ froφ 0,░ iε thσ to≡ lef⌠ corne≥ t∩ 23,7╣ iε thσ bottoφ ì
  132. righ⌠ « S∩ thσ firs⌠ threσ └ ..« SAY≤ outpu⌠ thσ men⌡ choice≤ oε threσ ì
  133. successivσ lines¼ 1▓ space≤ froφ thσ lef⌠ hanΣ edgσ oµ thσ screen« We'l∞ seσ ß ì
  134. lo⌠ morσ oµ └ ..« SA┘ later.
  135. 
  136. WAI╘ FO╥ I╘ 
  137.  
  138.           Thσ WAI╘ T╧ statemen⌠ get≤ thσ single-characte≥ selectioε froφ thσ ì
  139. user¼ anΣ thσ SE╘ CONSOL┼ command≤ whicΦ bracke⌠ i⌠ simpl∙ suppresse≤ thσ ì
  140. appearencσ oµ thσ WAITIN╟ messagσ tha⌠ woulΣ otherwisσ mes≤ u≡ ou≥ beautifu∞ ì
  141. screen« ┴ curiou≤ fac⌠ abou⌠ user≤ i≤ tha⌠ the∙ thinδ "aó anΣ "Aó arσ thσ samσ ì
  142. lette≥ - whicΦ the∙ obviousl∙ arσ not« T∩ overcomσ this¼ wσ conver⌠ an∙ lower-ì
  143. casσ int∩ upper-case¼ usinτ thσ !(⌐ function.
  144.  
  145.      No≈ come≤ thσ casσ statemen⌠ « Iε thσ firs⌠ tw∩ cases¼ wσ responΣ t∩ thσ ì
  146. user'≤ reques⌠ b∙ runninτ ß commanΣ filσ (ADDNAM.CM─ o≥ DELNAM.CMD)¼ bu⌠ ì
  147. noticσ iµ you≥ tryinτ thi≤ examplσ tha⌠ iµ yo⌡ don'⌠ cratσ thesσ file≤ you'l∞ ì
  148. ge⌠ aε erro≥ message« Eveε empt∙ file≤ wil∞ do¼ thougΦ yo⌡ won'⌠ seσ mucΦ ì
  149. happening.
  150.  
  151.      Fo≥ thσ qui⌠ option¼ wσ clea≥ thσ screeε beforσ CANCELlinτ thσ curren⌠ ì
  152. anΣ highe≥ commanΣ file≤ - iε othe≥ words¼ returninτ t∩ thσ commanΣ level« ì
  153. Finally¼ iµ wσ haven'⌠ recogniseΣ thσ user'≤ inpu⌠ b∙ thi≤ stage¼ wσ prin⌠ ì
  154. ASCI╔ characte≥ numbe≥ 7¼ whicΦ ring≤ thσ bel∞ o≥ beeps¼ anΣ theε redisplay≤ ì
  155. thσ menu.
  156.  
  157.      Ou≥ majo≥ examplσ thi≤ lessoε i≤ ß simplσ repor⌠ oε thσ booksho≡ ì
  158. database« Yo⌡ ma∙ recal∞ tha⌠ thσ BKINV.DB╞ ha≤ to∩ man∙ field≤ t∩ lis⌠ oε aε ì
  159. 8░ columε printer╗ iµ you'rσ lucky¼ your'≤ ma∙ wra≡ arounΣ automatically¼ bu⌠ ì
  160. minσ jus⌠ overtype≤ thσ samσ line« Ho≈ theε caε yo⌡ prin⌠ thσ content≤ oµ thσ ì
  161. database┐  Thσ prograφ list≤ thσ content≤ oµ thσ databasσ oε fivσ lines¼ witΦ ì
  162. ß sixtΦ linσ oµ dashe≤ t∩ separatσ eacΦ recorΣ froφ thσ next« I⌠ als∩ ì
  163. automaticall∙ insert≤ pagσ breaks.
  164. è               SE╘ TAL╦ OFF
  165.                US┼ bkinv
  166.                SE╘ FORMA╘ T╧ PRINT
  167.                SE╘ MARGI╬ T╧ 0
  168.                D╧ WHIL┼ .NOT« EOF
  169.                     STOR┼ ░ T╧ count
  170.                D╧ WHIL┼ coun⌠ ╝ 1░ .AND« .NOT« EOF
  171.                     STOR┼ coun⌠ ¬ ╢ T╧ pagepos
  172.                     └ pagepos+0¼ ░ SA┘ 'Stocδ Number:'
  173.                     └ pagepos+0,1┤ SA┘ stockno
  174.                     └ pagepos+1¼ ░ SA┘ 'Title:'
  175.                     └ pagepos+1¼ ╕ SA┘ title
  176.                     └ pagepos+2¼ ░ SA┘ "Author"
  177.                     └ pagepos+2¼ ╕ SA┘ author
  178.                     └ pagepos+3¼ ░ SA┘ "Publisher"
  179.                     └ pagepos+3,1▒ SA┘ publisher
  180.                     └ pagepos+3,2╖ SA┘ "Sel∞ Price"
  181.                     └ pagepos+3,3╣ SA┘ sell:price
  182.                     └ pagepos+3,5│ SA┘ "Bu∙ Price"
  183.                     └ pagepos+3,6┤ SA┘ buy:price
  184.                     └ pagepos+4¼ ░ SA┘ "Stocδ oε Hand"
  185.                     └ pagepos+4,1╡ SA┘ stock
  186.                     └ pagepos+4,2╖ SA┘ "Bacδ Ordered"
  187.                     └ pagepos+4,4▒ SA┘ backorder
  188.                     └ pagepos+5,5│ SA┘ "Reorde≥ Level"
  189.                     └ pagepos+4,6╕ SA┘ reorder
  190.                     └ pagepos+5,3░ SA┘ "------------------------------"
  191.                     SKIP
  192.                     STOR┼ COUN╘ +▒ T╧ count
  193.                ENDDO
  194.             ENDDO
  195.             SE╘ FORMA╘ T╧ SCREEN
  196.      Thi≤ i≤ ß reasonabl∙ straigh⌠ forwarΣ prograφ - i⌠ look≤ morσ comple° ì
  197. thaε i⌠ reall∙ is« Thσ firs⌠ fe≈ statement≤ opeε thσ databasσ filσ anΣ se⌠ thσ ì
  198. initia∞ conditions« SE╘ FORMA╘ T╧ PRIN╘ mean≤ tha⌠ subsequen⌠ └ ..« SAY'≤ wil∞ ì
  199. bσ sen⌠ t∩ thσ printer« Wσ havσ decideΣ t∩ prin⌠ ß recorΣ ove≥ si° lines¼ ì
  200. whicΦ mean≤ tha⌠ wσ caε fi⌠ teε oε ß page« S∩ wσ firs⌠ oµ al∞ se⌠ u≡ ß maiε ì
  201. loo≡ whicΦ print≤ ß pagσ a⌠ ß timσ - that'≤ thσ D╧ WHIL┼ .NOT« EOF« T∩ prin⌠ ß ì
  202. pagσ wσ simpl∙ coun⌠ teε records« Note¼ however¼ tha⌠ iµ wσ arσ onl∙ fivσ ì
  203. record≤ awa∙ froφ thσ enΣ oµ thσ filσ wheε wσ star⌠ printing¼ wσ can'⌠ prin⌠ ì
  204. teε record≤ (actuall∙ we'l∞ ge⌠ thσ las⌠ recorΣ printeΣ si° times)« S∩ wσ havσ ì
  205. t∩ includσ ß tes⌠ fo≥ end-of-file≤ iε thσ inne≥ loo≡ a≤ well.
  206.  
  207.      Nex⌠ wσ worδ ou⌠ thσ linσ wherσ thi≤ particula≥ recorΣ shoulΣ bσ printeΣ ì
  208. oε thσ pagσ - that'≤ coun⌠ si° times« Theε wσ prin⌠ thσ record¼ startinτ a⌠ ì
  209. tha⌠ line« Wheε aε └ ..« SA┘ i≤ sen⌠ t∩ thσ printer¼ dBasσ examine≤ thσ linσ ì
  210. numbe≥ iε relatioε t∩ it≤ curren⌠ linσ position« Iµ i⌠ i≤ alread∙ pas⌠ tha⌠ ì
  211. position¼ i⌠ wil∞ automaticall∙ inser⌠ ß pagσ ejec⌠ anΣ g∩ t∩ thσ righ⌠ ì
  212. positioε oε thσ nex⌠ pagσ - ß featurσ wσ coun⌠ oε t∩ ge⌠ pagσ eject≤ ever∙ teε ì
  213. records¼ a≤ thσ pagepo≤ goe≤ froφ 5┤ t∩ 0« A⌠ thσ enΣ oµ thσ loo≡ wσ ski≡ ì
  214. forwarΣ iε thσ database¼ incremen⌠ coun⌠ anΣ we'rσ done« Onσ thinτ t∩ watcΦ ì
  215. abou⌠ thi≤ (anΣ other⌐ commanΣ file≤ i≤ tha⌠ i⌠ leave≤ TAL╦ se⌠ OFF¼ s∩ tha⌠ ì
  216. iµ yo⌡ arσ experimentinτ witΦ dBase¼ o≥ makinτ adhoπ enquirie≤ usinτ SU═ o≥ ì
  217. COUNT¼ everythinτ wil∞ g∩ quiet.
  218.                                   END PART 7è