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

  1.                     PASCAL   FOR   BASIC   PROGRAMMERS
  2.  
  3.                                Dixon Kenney
  4.  
  5.                                  PART IX.             
  6.  
  7.      We'rσá no≈á goinτ t∩ adΣ t∩ ou≥ Inventor∙ Prograφ thσ procedurσá whicΦ ì
  8. wil∞ finΣ an∙ onσ item«á  Thi≤ procedurσ find≤ aε iteφ b∙ it≤ par⌠á number╗  ì
  9. i⌠á coulΣá bσ  rewritteε o≥  extendeΣ t∩ finΣ aε iteφá b∙á description¼á o≥ ì
  10. whateve≥ fielΣ yo⌡ required«  Here'≤ thσ codσ -
  11.  
  12. ááááProcedurσ  Finditem;
  13.  
  14. ááááConst
  15. áááá  Heade≥ ╜ º ¬ FIN─ A╬ EXISTIN╟ ITE═ O╞ STOC╦ ¬ ';
  16.  
  17. ááááVar
  18. áááá  P╬          ║ Integer;
  19. áááá  YesN∩       ║ Char;
  20. áááá  Agaiε       ║ Boolean;
  21. áááá  FounΣ       ║ Boolean;
  22.  
  23. ááááBegin
  24.  
  25. áááá  Assign(PartFile¼ FileName);
  26. áááá  Reset(PartFile);
  27.  
  28. áááá  Agaiε :╜ True;
  29.  
  30. áááá  Repeat
  31.  
  32. áááá    ClrScr;
  33. áááá    Writeln¿ º ':20¼ Header);
  34. áááá    Writeln╗ Writeln;
  35. áááá    Write('Ente≥ thσ Par⌠ Numbe≥ oµ thσ Iteφ requireΣ ║ ');
  36. áááá    Readln(PN);
  37.  
  38. áááá    WitΦ Par⌠ do
  39. áááá      Begin
  40. áááá        FounΣ :╜ False;
  41. áááá        Whilσ no⌠ EOF(PartFile⌐ anΣ no⌠ FounΣ do
  42. áááá          Begin
  43. áááá          Read(PartFile,Part);
  44. áááá          Iµ PartNuφ ╜ P╬ then
  45. áááá            FounΣ :╜ True;
  46. áááá          End;
  47.  
  48. áááá      Iµ no⌠ FounΣ then
  49. áááá        Begin
  50. áááá          Writeln╗  Writeln;
  51. áááá          Write('Thi≤ iteφ doe≤ no⌠ exis⌠ ');
  52. áááá        End
  53. áááá      Else
  54. áááá        Begin
  55. áááá          Formwrite(Header);
  56. áááá          Iµ DeleteΣ then
  57. áááá            Begin
  58. áááá              GoToXY(10,2);
  59. áááá              Write('¬ DELETE─ *');èáááá          End╗   √ oµ Iµ DeleteΣ }
  60. áááá          GoToXY(32¼ 4)╗ Write(PartNum);
  61. áááá          GoToXY(32¼ 5)╗ Write(Description);
  62. áááá          GoToXY(32¼ 7)╗ Write(Cost:8:2);
  63. áááá          GoToXY(32¼ 8)╗ Write(Retail:8:2);
  64. áááá          GoToXY(32,10)╗ Write(MinOH);
  65. áááá          GoToXY(32,11)╗ Write(MaxReorder);
  66. áááá          GoToXY(32,13)╗ Write(CurrentOH);
  67. áááá      End╗    √ oµ Elsσ .« }
  68. áááá    End;
  69. áááá    Writeln╗  Writeln;
  70.  
  71. áááá    Write('D∩ yo⌡ wan⌠ t∩ looδ fo≥ anothe≥ par⌠ █ Y/╬ ▌ ┐ ');
  72. áááá    Read(YesNo);
  73. áááá    Iµ UpCase(YesNo)╜ 'Y'
  74. áááá      Then
  75. áááá        Begin
  76. áááá          Agaiε :╜ True;
  77. áááá          Reset(PartFile)
  78. áááá        End
  79. áááá      Else
  80. áááá        Agaiε :╜ False
  81. áááá  Unti∞ Agaiε ╜ False;
  82.  
  83. áááá  Close(PartFile)
  84.  
  85. ááááEnd╗  √ Procedurσ FindIteφ )
  86.  
  87. Comments on the code -
  88.  
  89.      Ou≥ majo≥ probleφ t∩ addres≤ i≤ thi≤ - wha⌠ happen≤ iµ thσ iteφ i≤ no⌠ ì
  90. iε thσ datß list«  Wσ coulΣ havσ writteε thσ codσ t∩ finΣ i⌠ likσ thi≤ -
  91.  
  92. áááááááááRepeat     Read(PartFile)       Until PartNum = PN;
  93.  
  94.     However¼á iµ thσ iteφ i≤ no⌠ oε thσ list¼á thi≤ codσ wil∞ causσ thσ ì
  95. prograφ t∩ "bomΓ outó witΦ ß run-timσ erro≥ ¿ I'vσ trieΣ it¼ s∩ ╔ kno≈ tha⌠ ì
  96. thi≤ wil∞ happeε !⌐  S∩ wσ se⌠ tw∩ condition≤ -
  97.  
  98.      i⌐á   ReaΣá unti∞á thσ enΣ oµ thσ Filσ - Whilσá no⌠á EOF(filevariable⌐ ì
  99. mean≤á tha⌠á eacΦá recorΣ wil∞ bσ reaΣ iε turεá unti∞á thσá recorΣá pointe≥ ì
  100. reache≤ thσ EO╞ marker╗á thσ ReaΣ functioε wil∞ end¼ withou⌠ goinτ pas⌠ thσ ì
  101. marker;
  102.  
  103.      ii⌐  ReaΣ thσ filσ unti∞ thσ iteφ requireΣ i≤ found«  Wσ se⌠ ß Booleaε ì
  104. variablσ FOUN─ equa∞ t∩ FALS┼ wheε wσ ente≥ thσ loo≡ - i⌠ i≤ FALS┼ tha⌠ thσ ì
  105. iteφ ha≤ beeε FOUND«  Iµ wσ finΣ thσ item¼ thσ se⌠ thσ variablσ t∩ TRUE.
  106.  
  107.      Thσá tw∩ condition≤ meaε tha⌠ thσ ReaΣ wil∞ continuσ whilσ i⌠ i≤á TRU┼ ì
  108. botΦá tha⌠á wσ haven'⌠ reacheΣ thσ EnΣ oµ thσ Filσ anΣ als∩ thσ iteφá isn'⌠ ì
  109. FounΣ ¿ NO╘ FOUN─ mean≤ tha⌠ FOUN─ i≤ FALS┼ )«  However¼ a≤ sooε onσ oµ thσ ì
  110. condition≤ become≤ TRU┼ - tha⌠ is¼á NO╘ EO╞ o≥ NO╘ FOUN─ becomσ eithe≥á EO╞ ì
  111. o≥ FOUND¼ theε thσ ReaΣ loo≡ wil∞ terminatσ correctly.
  112.  
  113.      Iµ thσ flaτ FOUN─ remain≤ FALS┼ wheε thσ EO╞ i≤ reached¼á theε wσ havσ ì
  114. t∩á sa∙ tha⌠ thσ iteφ doesn'⌠ exis⌠ - whicΦ i≤ carrieΣ ou⌠ b∙ thσ I╞á blocδ ì
  115. oµ thσ I╞ NO╘ FOUN─ par⌠ oµ thσ code«  Iµ FOUN─ i≤ se⌠ t∩ TRUE¼ theε wσ caε ì
  116. writσá ou⌠á thσá detail≤ oε t∩ thσ screeε - thσ ELS┼ par⌠ oµ thσá I╞á FOUN─ ì
  117. block.è     In this block, notice the statement
  118.  
  119.                     If Deleted
  120.  
  121.     Thσá fielΣ DELETE─ i≤ ß Booleaε fielΣ - i⌠ caε havσ eithe≥á oµá thσ ì
  122. value≤ TRU┼ o≥ FALSE«  Thσ wa∙ t∩ se⌠ ß conditioε oε ß Booleaε fielΣ i≤ thσ ì
  123. wa∙ wσ havσ writteε it.
  124.  
  125.      If Deleted     means     if the field Deleted is set to TRUE
  126.      If NOT Deleted means     if the field Deleted is set to FALSE
  127.  
  128. Wσ don'⌠ havσ t∩ usσ thσ "=ó o≥ "<>ó sign≤ witΦ Booleaε variables.
  129.  
  130.      Towards the end of the procedure, we have the function
  131.  
  132.                UpCase(YesNo)
  133.  
  134.     Thi≤ functioε take≤ an∙ alphabetiπ character≤ iε thσ variable¼á anΣ ì
  135. treat≤á theφá al∞á a≤ iµ the∙ werσ Uppe≥ Casσ characters«á  Iεá ßá previou≤ ì
  136. procedure¼ wσ useΣ thσ phrase
  137.  
  138.                If variable in [ 'Y', 'y' ]
  139.  
  140. This is an alternative way of doing the same thing.
  141.  
  142.      Wheε wσ wrotσ thσ functioε EXISTS¼á wσ passeΣ ß valuσ t∩á it¼á througΦ ì
  143. thσ paramete≥ º (Namσ ║á Filespec⌐ ║ Booleaε '«  Wσ caε diagraφ it≤ workinτ ì
  144. likσ thi≤ -
  145.  
  146.              |------------------------|
  147. If Exists(FileName)                   |v
  148.       |^           Function Exists (Name : Filename ) : Boolean;
  149.       |                   Begin
  150.       |                   Exists := (IOResult = 0)
  151.       |---------------------|
  152.  
  153.      Wheε thσ functioε i≤ invoked¼ TurboPasca∞ make≤ ß copyô oµ thσ content≤ ì
  154. oµá thσ operanΣ oµ thσ functioε (FileName)¼á whicΦ i≤ useΣ b∙ thσá variablσ ì
  155. Namσ iε thσ Functioε itself«á  Wheneve≥ thσ functioε i≤ called¼ thσ datß i⌠ ì
  156. use≤á caεá bσ differen⌠ eacΦ timσ - thσ actua∞ valuσ i≤ substituteΣ iεá thσ ì
  157. functioεá call«á  Noticσá tha⌠á thσ variablσ i≤ declareΣá iεá thσá functioε ì
  158. 'titleºá - thi≤ i≤ calleΣ ß "forma∞ paramete≥ list"¼á anΣ thσ variable≤á d∩ ì
  159. no⌠ neeΣ t∩ bσ declareΣ iε thσ usua∞ way«  A⌠ thσ enΣ oµ thσ paramete≥ lis⌠ ì
  160. i≤á thσ typσ oµ thσ resul⌠ thσ functioε use≤ - iε thi≤ casσ ß Booleaε ¿á i≤ ì
  161. i⌠á TRU┼ tha⌠ thσ filσ exists¼á o≥ FALS┼ )«á  Al∞ variable≤ declareΣá iεá ß ì
  162. functioεá o≥á procedurσ arσ LOCA╠ t∩ tha⌠ block╗á tha⌠ is¼á the∙ canno⌠á bσ ì
  163. accesseΣ b∙ an∙ othe≥ blocδ iε thσ program¼á unles≤ i⌠ i≤ calleΣ froφ ¿ anΣ ì
  164. therefore¼ iε somσ wa∙ "nesteΣ in"⌐ thi≤ block«  So¼ iε Functioε Exists¼ a≤ ì
  165. sooε a≤ thσ functioε i≤ exited¼á thσ memor∙ useΣ b∙ thσ variablσ ╞ whicΦ wσ ì
  166. havσá declareΣá here¼á a≤ wel∞ a≤ Namσ iε thσá forma∞á paramete≥á list¼á i≤ ì
  167. releaseΣ b∙ thσ compiler¼ anΣ i≤ availablσ fo≥ useΣ again« 
  168.  
  169.      Thi≤á als∩á mean≤ that¼á iµ wσ havσ ß variablσ labelleΣ ╪ iε thσá maiε ì
  170. program¼ ß variablσ labelleΣ ╪ caε als∩ bσ declareΣ here¼ a≤ i⌠ exist≤ iε ß ì
  171. differen⌠ par⌠ oµ memory.
  172.  
  173.      Iε thσ nex⌠ part¼á wσ wil∞ talδ abou⌠ Paramete≥ passinτ t∩ Procedures¼ ì
  174. whicΦ i≤ aε extensioε oµ wha⌠ wσ havσ talkeΣ abou⌠ here« 
  175.                              END OF PART NINE.è