home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug003.arc / PASCAL.007 < prev    next >
Text File  |  1979-12-31  |  9KB  |  226 lines

  1.                     PASCAL   FOR   BASIC   PROGRAMMERS
  2.  
  3.                                Dixon Kenney
  4.  
  5.                                  PART VII          
  6.  
  7.      Iε thi≤ nex⌠ par⌠ iε thσ serie≤ oµ programminτ iε Pascal¼ wσ arσ goinτ ì
  8. t∩ writσ ß procedurσ b∙ whicΦ wσ caε adΣ aε iteφ oµ stocδ ¿ tha⌠ is¼ ß datß ì
  9. recorΣ ⌐ t∩ thσ datß file«á  Iε doinτ this¼á wσ arσ goinτ t∩ usσ ß mask¼ s∩ ì
  10. tha⌠á thσ operato≥ wh∩ i≤ fillinτ iε thσ informatioε wil∞ kno≈ exactl∙ wha⌠ ì
  11. informatioε wσ wan⌠ theφ t∩ typσ in«á  Mos⌠ oµ thσ prograφ i≤ lef⌠ out¼á a≤ ì
  12. i⌠á doesn'⌠á diffe≥á froφá thosσ iε previou≤á part≤á oµá thσá series«á  Thσ ì
  13. function≤ anΣ procedure≤ wσ havσ useΣ beforσ arσ indicateΣ b∙ thei≥ Includσ ì
  14. calls«á  Thσ linσ number¼ therefore¼ arσ no⌠ mean⌠ t∩ refe≥ t∩ thσ wholσ oµ ì
  15. thσ program«  The∙ arσ therσ simpl∙ fo≥ referencσ iε thσ text.
  16.  
  17.   1áá Prograφ Inventory_3;
  18.  
  19.   3áááType
  20.   4ááá  St3░     ╜ String[30];
  21.  
  22.   6áááVar
  23. áá7ááá  Heade≥     ║ St30;
  24.  
  25.  
  26.  10ááá{$╔ EXISTS.FN├ }
  27.  
  28.  
  29.  12ááá{$╔ CREATEFL.PR╧ }
  30.  
  31.  
  32.  14   {$╔ FWRITE.PR╧ }
  33.  
  34.  16 ááProcedurσ FormWritσ ¿ ╚ ║ St3░ );
  35.  
  36.  18áááConst
  37. á19ááá  TabΓ ╜ º               ';
  38.  
  39.  21áááBegin
  40.  
  41.  23ááá  ClrScr;
  42. á24ááá  Write(º ':25);
  43. á25ááá  Writeln(H);
  44. á26ááá  Writeln╗ Writeln;
  45. á27ááá  Writeln(Tabb¼ 'Par⌠ Numbe≥   ║ ');
  46. á28ááá  Writeln(Tabb¼ 'Descriptioε   ║ ');
  47. á29ááá  Writeln;
  48. á30ááá  Writeln(Tabb¼ 'Cos⌠ t∩ u≤    ║ ');
  49. á31ááá  Writeln(Tabb¼ 'Retai∞ Pricσ  ║ ');
  50. á32ááá  Writeln;
  51. á33ááá  Writeln(Tabb¼ 'Minimuφ Leve∞ ║ ');
  52. á34ááá  Writeln(Tabb¼ 'Maximuφ Leve∞ ║ ');
  53. á35ááá  Writeln;
  54. á36ááá  Writeln(Tabb¼ 'Oε HanΣ No≈   ║ ');
  55.  
  56.  38áááEnd╗    √ Procedurσ FormWritσ }
  57.  
  58.  41   {$╔ NEWITEM.PR╧ }
  59. è 43áááProcedurσ NewItem;
  60.  
  61. á45áááConst
  62. á46 áá  Heade≥ ╜ º ¬ AD─ ENTR┘ T╧ MASTE╥ FIL┼ *';
  63.  
  64. á48áááVar
  65. á49ááá  Agaiε  ║ Boolean;
  66. á50ááá  YesN∩  ║ Char;
  67.  
  68. á52áááBegin
  69.  
  70. á54ááá  Agaiε :╜ True;
  71.  
  72. á56ááá  Assign(PartFile¼ FileName);
  73. á57ááá  Reset(PartFile);
  74. á58ááá  Seek(PartFile¼ FileSize(PartFile));
  75.  
  76. á60ááá  Repeat
  77. á61ááá    FormWrite(Header);
  78. á62ááá    WitΦ Par⌠ do
  79. á63ááá      Begin
  80. á64ááá        GoToXY(32¼ 4)╗ Read(PartNum);
  81. á65ááá        GoToXY(32¼ 5)╗ Read(Description);
  82. á66ááá        GoToXY(32¼ 7)╗ Read(Cost);
  83. á67ááá        GoToXY(32¼ 8)╗ Read(Retail);
  84. á68ááá        GoToXY(32,10)╗ Read(MinOH);
  85. á69ááá        GoToXY(32,11)╗ Read(MaxReorder);
  86. á70ááá        GoTOXY(32,13)╗ Read(CurrentOH);
  87. á71 áá        Write(PartFile¼ Part)
  88. á72ááá    End;
  89.  
  90. á74ááá    Writeln╗ Writeln;
  91. á75ááá    Write('D∩ yo⌡ havσ anothe≥ par⌠ t∩ ente≥ [Y/N▌ ┐ ');
  92. á76ááá    Read(YesNo);
  93. á77ááá    Iµ YesN∩ iε █ 'Y'¼ 'y']
  94. á78ááá      theε Agaiε :╜ True
  95. á79ááá    Else
  96. á80ááá           Agaiε :╜ False
  97. á81ááá  Unti∞ Agaiε ╜ False;
  98.  
  99. á83ááá  Close(PartFile)
  100.  
  101. á85áááEnd╗   √ Procedurσ NewIteφ }
  102.  
  103.  87   {$╔ MENU.PR╧ }
  104.  
  105. á89áááBegin  { Main Section of the program }
  106.  
  107. á91ááá    Casσ Iteφ of
  108. á92ááá      1║ NewItem;
  109.  
  110. á94áááEnd.
  111.  
  112.  
  113.      Therσá arσ onσ o≥ tw∩ necessar∙ extrß declarations╗á wσ havσá onl∙á t∩ ì
  114. dea∞á witΦá thσ materia∞ iε thσ tw∩ ne≈ procedures«á  Let'≤ dea∞á witΦá thσ ì
  115. procedurσ FormWritσ first.
  116.  
  117. è     Thi≤á procedurσá exist≤ simpl∙ t∩ writσ ß datß masδ oε thσá screen«á ┴ ì
  118. masδá i≤ ß screeε whicΦ describe≤ thσ recorΣ iε word≤ whicΦá thσá oper-ato≥ ì
  119. caεá understand«á  "MinOHó migh⌠ bσ understooΣ b∙ thσ persoε wh∩ wrotσá thσ ì
  120. code¼á bu⌠á ß use≥ oµ thσ prograφ woulΣ understanΣ "Minimuφ Leveló ß littlσ ì
  121. morσá easily«á  Thσá detail≤á oµá eacΦ fielΣá oµá thσá recorΣá arσá printeΣ ì
  122. sequentiall∙ oε thσ screen.
  123.  
  124.      Iεá linσá 16¼á thσá procedurσ header¼á ß paramete≥ i≤á passeΣá t∩á thσ ì
  125. procedure«  I⌠ i≤ thσ Heade≥ fo≥ thσ screeε mask«  Thi≤ particula≥ masδ caε ì
  126. bσá useΣá fo≥ morσ thaε th≤ procedure¼á sincσ i⌠ describe≤ eacΦá recorΣá iε ì
  127. full«á  So¼á wσá pas≤ t∩ thσ procedurσ whicΦ use≤ thσ masδ thσ titlσ oµ thσ ì
  128. mask¼á whicΦ i≤ se⌠ u≡ iε thσ callinτ procedure¼á herσ linσ 46«  B∙ passinτ ì
  129. thi≤ header¼á mucΦ codσ writinτ i≤ saved¼á sincσ wσ d∩ no⌠ neeΣ t∩ writσá ß ì
  130. masδ fo≥ eacΦ individua∞ procedure.
  131.  
  132.      No≈á let'≤ movσ oε t∩ thσ nex⌠ procedurσ - Procedurσá NewItem«á  Therσ ì
  133. arσ ß numbe≥ oµ item≤ t∩ looδ a⌠ here«á  Thi≤ procedurσ i≤ calleΣ froφ linσ ì
  134. 92¼ whicΦ i≤ par⌠ oµ thσ Casσ statemen⌠ iε thσ Maiε blocδ oµ thσ program.
  135.  
  136.      Iε linσ 57¼ thσ filσ whicΦ ha≤ beeε previousl∙ createΣ i≤ opened«  Thσ ì
  137. functioεá Rese⌠á open≤á aε alread∙ createΣ file«á  Herσ i⌠ open≤á thσá filσ ì
  138. referreΣ t∩ b∙ thσ filσ variablσ PartFile¼ tha⌠ is¼ "INVENT.DAT"«  Wheε thσ ì
  139. filσ i≤ opened¼á thσ recorΣ pointe≥ i≤ se⌠ t∩ poin⌠ a⌠ thσ beginninτ oµ thσ ì
  140. file¼á tha⌠ is¼ t∩ recorΣ 0«  Thσ filσ i≤ closeΣ iε linσ 83¼ usinτ thσ samσ ì
  141. functioε a≤ wσ useΣ iε thσ CreateFilσ proced-urσ - Close«  Iε betweeε thesσ ì
  142. tw∩ functions¼ wσ d∩ ß lo⌠ oµ work.
  143.  
  144.      Iε linσ 58¼á wσ pu⌠ thσ recorΣ pointe≥ t∩ thσ enΣ oµ thσá file«á  Thi≤ ì
  145. linσá contain≤ tw∩ functions«á  Thσ functioε Seek(filevariable,n)ô move≤ thσ ì
  146. recorΣá pointe≥ througΦ thσ filσ 'filevariableº unti∞ i⌠ point≤á a⌠á recorΣ ì
  147. numbe≥á 'n'«á  Thi≤ functioε caε bσ useΣ a⌠ an∙ timσ t∩ acces≤ ß particula≥ ì
  148. recorΣ iµ thσ numbe≥ oµ thσ recorΣ i≤ known.
  149.  
  150.      Iεá orde≥ t∩ appenΣ ß recorΣ t∩ thσ file¼á wσ mus⌠ movσ t∩ thσ enΣá oµ ì
  151. thσ filσ - tha⌠ is¼á t∩ thσ recorΣ nex⌠ pas⌠ thσ fina∞ recorΣ oµ thσá file«  ì
  152. Thi≤á i≤ donσ b∙ usinτ thσ functioε FileSize(filevariable)«á  Thi≤ functioε ì
  153. count≤ thσ numbe≥ oµ record≤ iε thσ file«á  So¼á iµ wσ haΣ ╕á records¼á thσ ì
  154. functioε return≤ thσ numbe≥ 8«  However¼ sincσ thσ firs⌠ recorΣ i≤ numbereΣ ì
  155. 0¼ thσ fina∞ actua∞ recorΣ i≤ numbe≥ 7¼ anΣ thσ Seeδ functioε i≤ positioneΣ ì
  156. t∩á poin⌠á t∩ thσ nex⌠ recorΣ t∩ bσ appendeΣ t∩ thσ file«á  Notσ tha⌠á thi≤ ì
  157. functioε i≤ oµ typσ integer¼á anΣ thσ numbe≥ 'nº supplieΣ t∩ Seeδ mus⌠ als∩ ì
  158. bσ oµ typσ Integer.
  159.  
  160.      No≈ looδ a⌠ linσ 6▓ - WIT╚ Par⌠ DO«á  Wheε wσ wan⌠ t∩ acces≤ ß record¼ ì
  161. wσá caε finΣ ourselve≤ iε ß bi⌠ oµ trouble¼á a≤ wσ usuall∙ wan⌠ t∩ worδá oε ì
  162. thσ individua∞ field≤ oµ eacΦ record«á  Iε Pascal¼ wσ caε referencσ eacΦ oµ ì
  163. thσ field≤ oµ ß record≤ b∙ usinτ ß fielΣ selector«á  Thi≤ fielΣ selecto≥ i≤ ì
  164. madσ u≡ oµ thσ recorΣ namσ followeΣ b∙ ß perioΣ followeΣ b∙ thσ fielΣ name«  ì
  165. S∩ here¼ t∩ acces≤ eacΦ field¼ wσ woulΣ havσ t∩ say¼ fo≥ example
  166.  
  167.      Part.Partnuφ             Part.Retai∞         Part.CurrentOH
  168.  
  169.      I⌠á woulΣ bσ mucΦ easie≥ fo≥ u≤ iµ wσ werσ ablσ t∩ acces≤á eacΦá fielΣ ì
  170. simpl∙á b∙ it≤ owε label¼á withou⌠ thσ neeΣ fo≥ thσ prefixeΣ recorΣá label«  ì
  171. Wσ caε makσ thing≤ mucΦ shorte≥ b∙ usinτ thi≤ WIT╚ statement¼ a≤ yo⌡ seσ i⌠ ì
  172. useΣ here«  Thσ synta° i≤ quitσ simplσ -
  173.  
  174.                  WIT╚ record_variable_labe∞ D╧ statement.
  175. è     Thσ 'statementº par⌠ i≤ wha⌠ yo⌡ wan⌠ t∩ d∩ witΦ thσ individua∞ field≤ ì
  176. oµá thσá recorΣá yo⌡á arσ accessing«á  I⌠ ma∙ bσ a≤á simplσá o≥á comple°á ß ì
  177. statemen⌠á a≤á yo⌡ wish«á  Thσ WIT╚ statemen⌠ caε bσ mucΦ morσá complicateΣ ì
  178. thaεá thi≤ - you≥ Turb∩ Pasca∞ manua∞ wil∞ sho≈ yo⌡ ho≈ iµ yo⌡á arσá reall∙ ì
  179. interested¼ bu⌠ thi≤ i≤ complicateΣ enougΦ fo≥ u≤ now.
  180.  
  181.      Iεá line≤ 64µ (anΣ iε linσ 14╩ oµ thσ previou≤ prograφ iε par⌠ VI⌐á wσ ì
  182. havσ ß simplσ curso≥ positioninτ statement.
  183.  
  184. áááááááááThi≤á i≤á equivalen⌠á t∩á MicroWorlΣá Basic'≤á CUR╙ ì
  185. ááááááááástatement¼ anΣ i≤ useΣ iε mucΦ thσ samσ way¼ a≤ yo⌡ ì
  186. ááááááááácan see. 
  187.  
  188.      Thσ curso≥ i≤ moveΣ t∩ thσ positioε oε thσ screeε indicateΣ b∙ thσ tw∩ ì
  189. intege≥á number≤ oε whicΦ thσ functioε operates«á  Thσ firs⌠ i≤ thσá columε ì
  190. number¼á anΣ thσ seconΣ thσ row«  NB«  Thi≤ i≤ thσ reversσ oµ thσ situatioε ì
  191. a≤ describeΣ iε thσ Manual¼ whicΦ say≤ thσ functioε i≤ row¼ column«  
  192.  
  193.      Iε thi≤ function¼á thσ curso≥ i≤ positioneΣ iε turε a⌠ thσ enΣ oµ eacΦ ì
  194. oµá thσá prompt≤á printeΣ oε thσ screeε b∙ thσ mask«á  Thi≤á prevent≤á botΦ ì
  195. scrollinτ oµ thσ screeε anΣ overwritinτ oµ informatioε oε it.
  196.  
  197.      Iε linσ 71¼á afte≥ al∞ thσ informatioε i≤ obtained¼á wσ actuall∙ writσ ì
  198. thσáá recorΣá t∩á disk¼áá usinτá thσá thσáá procedurσáá WRITE(filevariable¼ ì
  199. recordvariable)«á  Thi≤ functioε differ≤ froφ mos⌠ othe≥ Pascals¼ whicΦ usσ ì
  200. thσ procedurσ PUT«  Iµ yo⌡ arσ writinτ iε anothe≥ versioε oµ Pascal¼ havinτ ì
  201. learn⌠ TPascal¼á theε bσ ver∙ carefu∞ oµ this¼á anΣ finΣ ou⌠ jus⌠ wha⌠ you≥ ì
  202. ne≈ version'≤ synta° is.
  203.  
  204.      Finally¼á wσ comσ t∩ thσ concep⌠ oµ ß set¼á iε linσ 77«  Iε Pascal¼ wσ ì
  205. arσá ablσá t∩ definσ sets¼á whicΦ thσ manua∞ describe≤ a≤ "collect-ion≤á oµ ì
  206. relateΣá object≤ whicΦ ma∙ bσ though⌠ oµ a≤ ß whole.ó  Thσ member≤á oµá thσ ì
  207. se⌠ ¿ eacΦ oµ it≤ individua∞ item≤ ⌐ mus⌠ bσ oµ thσ samσ type¼ whicΦ caε bσ ì
  208. an∙ scala≥ typσ excep⌠ typσ REAL.
  209.  
  210.      Herσá wσ simpl∙ writσ ß conditiona∞ statement¼á t∩ seσ iµ thσ content≤ ì
  211. oµ ß variablσ exis⌠ withiε ß set«á  Noticσ tha⌠ thσ member≤ oµ thσ se⌠á arσ ì
  212. defineΣ betweeε squarσ brackets¼ eacΦ separateΣ froφ thσ other≤ b∙ ß comma¼ ì
  213. and¼á iε thσ casσ oµ characters¼ delimiteΣ b∙ singlσ quotσ marks«   ┴ rangσ ì
  214. oµá se⌠á member≤á caεá bσ expresseΣ b∙ separatinτ thσá lowes⌠á anΣá highes⌠ ì
  215. element≤ oµ thσ rangσ b∙ tw∩ consecutivσ periods¼ likσ thi≤ -
  216.  
  217.                   [ 'A'..'Z' , 'a'..'z' , '0'..'9' ]  
  218.  
  219. Iε thi≤ line¼ wσ arσ writinτ ß mucΦ simple≥ wa∙ oµ saying
  220.  
  221.                     If YesNo = 'Y' or YesNo = 'y'
  222.  
  223.      Yo⌡ caε seσ ho≈ mucΦ spacσ i≤ saveΣ iε ou≥ codσ iµ therσ arσ morσ thaε ì
  224. tw∩ element≤ iε thσ se⌠ beinτ tested«              
  225.  
  226.                             END OF PART SEVEN.