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

  1. PASCAL   FOR   BASIC   PROGRAMMERS
  2.  
  3.                                Dixon Kenney
  4.  
  5.                                   PART X.              
  6.  
  7.      Thi≤á montΦá wσ arσ goinτ t∩ writσ thσ procedurσ whicΦ wil∞á edi⌠á an∙ ì
  8. item«á  A≤á wel∞ a≤ editinτ aε item¼á s∩ tha⌠ an∙ fielΣ caε bσ changed¼á wσ ì
  9. wil∞ havσ aε optioε whereb∙ thσ iteφ caε bσ markeΣ fo≥ deletion«á  Wσá onl∙ ì
  10. marδ thσ item¼á s∩ that¼á durinτ aε editinτ session¼á wσ caε unmarδ it¼á iµ ì
  11. necessary«á  Thσ actua∞ deletioε wil∞ bσ donσ b∙ ß separatσ function¼ whicΦ ì
  12. wσ wil∞ looδ a⌠ nex⌠ time.
  13.  
  14. áááááááááProgrammer≤á iεá dBAS┼á I╔ wil∞ recognisσá thi≤á wa∙á oµ ì
  15. ááááááááádeletinτá aε iteφ froφ ß database«á  Thi≤ wa∙ mean≤ tha⌠ ì
  16. áááááááááthσá iteφá i≤ no⌠ deleteΣ unti∞ wσ arσ finall∙á surσá oµ ì
  17. áááááááááwha⌠ wσ arσ doinτ - i⌠ give≤ u≤ thσ chancσ t∩ changσ ou≥ ì
  18. ááááááááámind.
  19.  
  20. Procedure  Edit;
  21.  
  22. Const
  23.   Header  =  '* EDIT AN EXISTING ITEM OF STOCK *';
  24.  
  25. Var
  26.   PN, Pointer, Option  : Integer;
  27.   Again, Found, More   : Boolean;
  28.   YesNo, Yeah          : Char;
  29.  
  30. Begin
  31.  
  32.   Assign(PartFile, FileName);
  33.   Reset(PartFile);
  34.  
  35.   Again := True;
  36.  
  37.   Repeat
  38.     ClrScr;
  39.     Writeln(' ':20, Header );
  40.     Writeln;  Writeln;
  41.     Write('Enter the Part Number of the item required : ');
  42.     Readln(PN);
  43.  
  44.     With Part Do
  45.       Begin
  46.         Found := False;
  47.         While not EOF(PartFile) and not Found do
  48.           Begin
  49.             Read(PartFile, Part);
  50.             If PartNum = PN then
  51.               Found := True;
  52.             End;
  53.  
  54.         If not Found then
  55.           Begin
  56.             Writeln;  Writeln;
  57.             Writeln('This item does not exist');
  58.           End
  59.         Elseè          Begin
  60.             More := True;
  61.             Pointer := FilePos(PartFile);
  62.             Repeat
  63.               Formwrite(Header);
  64.               GoToXY(32, 4); Write(PartNum);
  65.               GoToXY(32, 5); Write(Description);
  66.               GoToXY(32, 7); Write(Cost:8:2);
  67.               GoToXY(32, 8); Write(Retail:8:2);
  68.               GoToXY(32,10); Write(MinOH);
  69.               GoToXY(32,11); Write(MaxReorder);
  70.               GoToXY(32,13); Write(CurrentOH);
  71.               GoToXY( 1,18);
  72.               Writeln('Type in the number of the field you wish to alter');
  73.               Write('  or  99  to delete this item  ');
  74.               Read(Option);
  75.  
  76.               Case Option of
  77.                 1 : Begin GoToXY(32, 4); ClrEOL; Read(PartNum)   End;
  78.                 2 : Begin GoToXY(32, 5); ClrEOL; Read(Description)   End;
  79.                 3 : Begin GoToXY(32, 7); ClrEOL; Read(Cost)   End;
  80.                 4 : Begin GoToXY(32, 8); ClrEOL; Read(Retail)   End;
  81.                 5 : Begin GoToXY(32,10); ClrEOL; Read(MinOH)   End;
  82.                 6 : Begin GoToXY(32,11); ClrEOL; Read(MaxReorder)   End;
  83.                 7 : Begin GoToXY(32,13); ClrEOL; Read(CurrentOH)   End;
  84.                99 : Begin Deleted := Not Deleted;
  85.                     If Deleted then
  86.                       Begin  GoToXY(10,2); Write ('* DELETED *')  End
  87.                     Else  Begin  GoToXY(10,2); ClrEOL  End;
  88.                     End   { of Case = 99 }
  89.               Else Begin
  90.                 GoToXY(1,22); Writeln('Not a valid option - try again');
  91.                 Delay(2000); GoToXY(1,22); ClrEOL
  92.               End    { Else }
  93.               End;   { Case Option }
  94.  
  95.               GoToXY(1,22);
  96.               Write('Do you have another entry for this item [Y/N] ?');
  97.               Read(Yeah);
  98.               If UpCase(Yeah) = 'Y'
  99.                 Then More := True
  100.                 Else More := False
  101.            Until More = False;
  102.  
  103.            Seek(PartFile,Pointer-1);
  104.            Write(PartFile, Part);
  105.  
  106.          End     { of If Found }
  107.        End;      { of With Part do }
  108.        Writeln;   Writeln;
  109.  
  110.        Write('Do you want to look for another part [Y/N] ? ');
  111.        Read(YesNo);
  112.        If UpCase(YesNo) = 'Y' then
  113.          Begin
  114.          Again := True;
  115.          Reset(PartFile)
  116.          End
  117.        Elseè         Again := False
  118.      Until Again = False;
  119.      Close(PartFile)
  120.  
  121. End;      { of Procedure Edit }
  122.  
  123. Comments on the code -
  124.  
  125.     MucΦá oµá wha⌠á i≤á donσ herσ i≤ repeateΣá froφá othe≥á procedures¼ ì
  126. especiall∙ Procedurσ FindItem«á Wσ havσ t∩ finΣ thσ item¼á anΣ prin⌠ i⌠á t∩ ì
  127. thσá screen«á  Oncσ tha⌠ i≤ done¼á wσ caε choosσ item≤ t∩ edit«á  Thσá casσ ì
  128. Optioε statemen⌠ shoulΣ bσ familiar¼á excep⌠ fo≥ thσ ClrEO╠ function«  Thi≤ ì
  129. functioεá clear≤ thσ curren⌠ screeε linσ froφ thσ positioε oµ thσ curso≥ t∩ ì
  130. thσ enΣ oµ thσ line¼á bu⌠ i≤ doe≤ NO╘ movσ thσ cursor«á  Here¼ i⌠ blot≤ ou⌠ ì
  131. thσ curren⌠ valuσ oµ thσ fielΣ whicΦ ha≤ beeε chosen¼á allowinτ thσ use≥ t∩ ì
  132. typσ iε anothe≥ value¼á whicΦ i≤ theε read«á  Thσ FormWritσ listinτ ha≤á t∩ ì
  133. modifieΣá s∩á tha⌠ choicσ number≤ arσ addeΣ beforσ eacΦ fielΣ labe∞á - thi≤ ì
  134. give≤á u≤ thσ variou≤ number≤ t∩ choose«á  Choicσ 9╣ wil∞ alte≥á thσá fielΣ ì
  135. Deleted¼á whicΦá wa≤á se⌠ t∩ Falsσ a⌠ datß entry¼á t∩ True«á  Wheneve≥á thσ ì
  136. inidividua∞á iteφ i≤ listeΣ oε thσ screen¼á thσ strinτ "¬ DELETE─á *óá wil∞ ì
  137. appea≥á a⌠á thσ heaΣ oµ thσ listing¼á t∩ sho≈ tha⌠ thσ iteφ i≤á markeΣá fo≥ ì
  138. deletion«  B∙ typinτ 9╣ ß seconΣ time¼ thσ iteφ caε bσ undeleted.
  139.  
  140.      Oncσá thσ editinτ oµ thσ iteφ ha≤ beeε finished¼á wσ mus⌠ rewritσá thσ ì
  141. recorΣ t∩ disk«á  Wheε wσ accesseΣ thσ recorΣ witΦ thσ ReaΣ state-ment¼ thσ ì
  142. Filσá Pointe≥ wa≤ moveΣ t∩ poin⌠ t∩ thσ followinτ record«á  S∩ tha⌠ wσá caε ì
  143. writσ thσ RecorΣ bacδ t∩ thσ correc⌠ placσ iε thσ file¼ wσ havσ t∩ movσ thσ ì
  144. recorΣ pointe≥ bacδ onσ placσ t∩ poin⌠ t∩ thσ correc⌠ record«  Thi≤ i≤ donσ ì
  145. iεá thσ "Seek(PartFile¼á Pointer-1)ó statement«á  Thσ valuσ oµ thσá curren⌠ ì
  146. record'≤ pointe≥ wa≤ storeΣ wheε i⌠ wa≤ found¼á beforσ wσ wrotσ i⌠ t∩ disk¼ ì
  147. iε thσ variablσ Pointer«á  Wheε thi≤ statemen⌠ i≤ executed¼á thσ pointe≥ i≤ ì
  148. moveΣá agaiε froφ thσ beginninτ oµ thσ filσ t∩ thσ correc⌠ record«á  Wσ caε ì
  149. theε writσ thσ recorΣ t∩ thσ filσ witΦ thσ usua∞ Writσ statement.
  150.  
  151.      Iµá wσá wan⌠á t∩ acces≤ anothe≥ record¼á wσ havσá t∩á star⌠á froφá thσ ì
  152. beginninτ oµ thσ filσ again¼á sincσ thσ ne≈ recorΣ ma∙ bσ positioneΣ beforσ ì
  153. thσ currentl∙ accesseΣ record«  S∩ wσ havσ t∩ Rese⌠ thσ filσ iε thσ "D∩ yo⌡ ì
  154. wan⌠ another?ó section¼ iµ tha⌠ choicσ i≤ made.
  155.  
  156.      Iεá thσá previou≤á par⌠á oµá thi≤á series¼á wσá talkeΣá abou⌠á passinτ ì
  157. parameter≤á t∩ ß Function«á  Thσ actua∞ situatioε oµ paramete≥ passinτ i≤ ß ì
  158. littlσ morσ complicateΣ thaε wha⌠ wσ saiΣ there¼ however.
  159.  
  160.      Wheεá wσ passeΣ thσ paramete≥ oµ thσ FileNamσ iε thσ Functioεá Exists¼ ì
  161. wσá actuall∙ onl∙ madσ ß cop∙ oµ thσ valuσ oµ thσ FileName¼á anΣ workeΣá oε ì
  162. it«  Thi≤ i≤ calleΣ ß "valueó paramete≥ - wheε thσ procedurσ i≤ called¼ thσ ì
  163. paramete≥ iε thσ calleΣ procedurσ i≤ initializeΣ t∩ thσ valuσ oµ thσ actua∞ ì
  164. paramete≥ whicΦ correspond≤ t∩ i⌠ iε thσ call«á  Thσ actua∞ variablσ iε thσ ì
  165. callinτ statemen⌠ i≤ protecteΣ froφ change.
  166.  
  167.      However¼á wσ ma∙ wan⌠ t∩ manipulatσ thσ actua∞ valuσ itself¼á anΣá no⌠ ì
  168. jus⌠á ß cop∙ oµ it«á  Wσ d∩ thi≤ b∙ passinτ t∩ thσ procedurσ thσ Addres≤ oµ ì
  169. thσ valuσ iε memory¼á s∩ tha⌠ thσ procedurσ manipulate≤ i⌠á directly«á  Thσ ì
  170. paramete≥á iεá thσ procedurσ heade≥ i≤ theε calleΣ ß "variableóá parameter«  ì
  171. I⌠á i≤ formeΣ b∙ writinτ thσ reserveΣ worΣ VA╥ iε fron⌠ oµ thσ variablσá o≥ ì
  172. variable≤ b∙ whicΦ wσ arσ goinτ t∩ manip-ulatσ thσ value.
  173.  
  174.  
  175. è     Herσ i≤ aε examplσ oµ Variablσ paramete≥ passinτ  ¿ takeε froφ thσá T╨ ì
  176. Manual¼á p«á 132«á  Thσá Manua∞á ╔á aφá usinτá i≤ tha⌠á fo≥á Versioεá │á oµ ì
  177. TurboPascal.)
  178.  
  179.      Procedure Switch ( Var a, b : Integer );
  180.      Var    Tmp : Integer;
  181.      begin
  182.           Tmp := a; a := b; b := Tmp;
  183.      end;
  184.  
  185. áááááááááThσá callinτ statemen⌠ -  Switch¿ i,Ω )╗á  wil∞ actuall∙ ì
  186. áááááááááswitcΦ thσ value≤ oµ "ió anΣ "j"¼ whicΦ arσ addresseΣ iε ì
  187. áááááááááthσ procedurσ b∙ thσ variablσ label≤ "aó anΣ "b".
  188.  
  189. ááááááááá     BotΦá Function≤ anΣ Procedure≤ caε usσ eithe≥á typσ ì
  190. áááááááááoµ paramete≥ passing¼á anΣ thσ tw∩ type≤ caε bσ mixeΣ iε ì
  191. áááááááááonσ procedurσ o≥ function«á  Herσ i≤ aε example¼ usinτ ß ì
  192. áááááááááprocedurσ whicΦ compute≤ thσ intege≥ anΣ factiona∞ part≤ ì
  193. áááááááááoµá ßá number«á  (Examplσ froφ "Probleφá Solvinτá .«á iε ì
  194. áááááááááPascal¼áá b∙á Koffman¼á p.170¼á ßá booδá I'vσá mentioneΣ ì
  195. ááááááááábefore.)
  196.  
  197. áááááProcedure Breakdown ( x    : Real;
  198. ááááá                 Var Frac  : Real;
  199. ááááá                 Var Whole : Integer);
  200.  
  201. áááááBegin
  202. ááááá  Whole := Trunc(x);
  203. ááááá  Frac  := x - whole
  204. áááááEnd;
  205.  
  206. This procedure is called by the statement
  207.  
  208.      Breakdown ( a, r, i);
  209.      Writeln(a:7:2, r:7:2, i:7);
  210.  
  211. áááááááááwherσ "aó i≤ ß rea∞ number¼á whosσ valuσ i≤ passeΣá int∩ ì
  212. ááááááááá"xóá ("aóá itselµá i≤ no⌠ changeΣ b∙á thσá procedurσá )╗ ì
  213. ááááááááá"Fracó anΣ "Wholeó actuall∙ manipulatσ thσ variable≤ "ró ì
  214. ááááááááá(ßá real⌐ anΣ "ió (aε integer)¼á anΣ s∩ havσ thσ VA╥á iε ì
  215. áááááááááfron⌠ oµ theφ iε thσ paramete≥ string.
  216.  
  217. ááááááááá     Iµá "aóá haΣá thσá valuσ 1.2│á wheεá Breakdowεá wa≤ ì
  218. ááááááááácalled¼ thσ Writelε statemen⌠ woulΣ producσ thσ resul⌠ -    ì
  219. ááááááááá1.2│     0.2│    1
  220. ááááááááá
  221. ááááááááá"róá anΣá "ió receivσ thei≥ value≤ froφá thσá procedure¼ ì
  222. ááááááááárathe≥ thaε iε thσ callinτ program«  Thσ value≤ computeΣ ì
  223. áááááááááiεá thσ procedurσ arσ addres-seΣ b∙ theφ - the∙ arσá no⌠ ì
  224. ááááááááácopie≤ oµ thσ procedurσ values.
  225.  
  226. ááááááááá     Valuσá parameter≤ ¿ n∩ Va≥ ⌐ arσ one-wa∙á channels¼ ì
  227. áááááááááfroφ cal∞ t∩ procedurσ o≥ function«  Variablσ parameter≤ ì
  228. ááááááááá¿ witΦ VA╥ ⌐ arσ two-wa∙ communicatioε channels.
  229.  
  230.      Therσá i≤ mucΦ morσ t∩ learε iε Pascal¼á bu⌠ yo⌡ caε g∩ oε froφá here¼ ì
  231. I'φ sure«  Koffman'≤ book≤ wil∞ bσ ß grea⌠ hel≡ t∩ you«  Oncσ you'vσ learn⌠ ì
  232. Pascal¼á you'l∞ finΣ i⌠ ß better¼á albei⌠ ß longer¼ wa∙ oµ programminτ thaε ì
  233. programminτ iε Basic.è