home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug003.arc
/
PASCAL.010
< prev
next >
Wrap
Text File
|
1979-12-31
|
10KB
|
233 lines
PASCAL FOR BASIC PROGRAMMERS
Dixon Kenney
PART X.
Thi≤á montΦá wσ arσ goinτ t∩ writσ thσ procedurσ whicΦ wil∞á edi⌠á an∙ ì
item«á A≤á wel∞ a≤ editinτ aε item¼á s∩ tha⌠ an∙ fielΣ caε bσ changed¼á wσ ì
wil∞ havσ aε optioε whereb∙ thσ iteφ caε bσ markeΣ fo≥ deletion«á Wσá onl∙ ì
marδ thσ item¼á s∩ that¼á durinτ aε editinτ session¼á wσ caε unmarδ it¼á iµ ì
necessary«á Thσ actua∞ deletioε wil∞ bσ donσ b∙ ß separatσ function¼ whicΦ ì
wσ wil∞ looδ a⌠ nex⌠ time.
áááááááááProgrammer≤á iεá dBAS┼á I╔ wil∞ recognisσá thi≤á wa∙á oµ ì
ááááááááádeletinτá aε iteφ froφ ß database«á Thi≤ wa∙ mean≤ tha⌠ ì
áááááááááthσá iteφá i≤ no⌠ deleteΣ unti∞ wσ arσ finall∙á surσá oµ ì
áááááááááwha⌠ wσ arσ doinτ - i⌠ give≤ u≤ thσ chancσ t∩ changσ ou≥ ì
ááááááááámind.
Procedure Edit;
Const
Header = '* EDIT AN EXISTING ITEM OF STOCK *';
Var
PN, Pointer, Option : Integer;
Again, Found, More : Boolean;
YesNo, Yeah : Char;
Begin
Assign(PartFile, FileName);
Reset(PartFile);
Again := True;
Repeat
ClrScr;
Writeln(' ':20, Header );
Writeln; Writeln;
Write('Enter the Part Number of the item required : ');
Readln(PN);
With Part Do
Begin
Found := False;
While not EOF(PartFile) and not Found do
Begin
Read(PartFile, Part);
If PartNum = PN then
Found := True;
End;
If not Found then
Begin
Writeln; Writeln;
Writeln('This item does not exist');
End
Elseè Begin
More := True;
Pointer := FilePos(PartFile);
Repeat
Formwrite(Header);
GoToXY(32, 4); Write(PartNum);
GoToXY(32, 5); Write(Description);
GoToXY(32, 7); Write(Cost:8:2);
GoToXY(32, 8); Write(Retail:8:2);
GoToXY(32,10); Write(MinOH);
GoToXY(32,11); Write(MaxReorder);
GoToXY(32,13); Write(CurrentOH);
GoToXY( 1,18);
Writeln('Type in the number of the field you wish to alter');
Write(' or 99 to delete this item ');
Read(Option);
Case Option of
1 : Begin GoToXY(32, 4); ClrEOL; Read(PartNum) End;
2 : Begin GoToXY(32, 5); ClrEOL; Read(Description) End;
3 : Begin GoToXY(32, 7); ClrEOL; Read(Cost) End;
4 : Begin GoToXY(32, 8); ClrEOL; Read(Retail) End;
5 : Begin GoToXY(32,10); ClrEOL; Read(MinOH) End;
6 : Begin GoToXY(32,11); ClrEOL; Read(MaxReorder) End;
7 : Begin GoToXY(32,13); ClrEOL; Read(CurrentOH) End;
99 : Begin Deleted := Not Deleted;
If Deleted then
Begin GoToXY(10,2); Write ('* DELETED *') End
Else Begin GoToXY(10,2); ClrEOL End;
End { of Case = 99 }
Else Begin
GoToXY(1,22); Writeln('Not a valid option - try again');
Delay(2000); GoToXY(1,22); ClrEOL
End { Else }
End; { Case Option }
GoToXY(1,22);
Write('Do you have another entry for this item [Y/N] ?');
Read(Yeah);
If UpCase(Yeah) = 'Y'
Then More := True
Else More := False
Until More = False;
Seek(PartFile,Pointer-1);
Write(PartFile, Part);
End { of If Found }
End; { of With Part do }
Writeln; Writeln;
Write('Do you want to look for another part [Y/N] ? ');
Read(YesNo);
If UpCase(YesNo) = 'Y' then
Begin
Again := True;
Reset(PartFile)
End
Elseè Again := False
Until Again = False;
Close(PartFile)
End; { of Procedure Edit }
Comments on the code -
MucΦá oµá wha⌠á i≤á donσ herσ i≤ repeateΣá froφá othe≥á procedures¼ ì
especiall∙ Procedurσ FindItem«á Wσ havσ t∩ finΣ thσ item¼á anΣ prin⌠ i⌠á t∩ ì
thσá screen«á Oncσ tha⌠ i≤ done¼á wσ caε choosσ item≤ t∩ edit«á Thσá casσ ì
Optioε statemen⌠ shoulΣ bσ familiar¼á excep⌠ fo≥ thσ ClrEO╠ function« Thi≤ ì
functioεá clear≤ thσ curren⌠ screeε linσ froφ thσ positioε oµ thσ curso≥ t∩ ì
thσ enΣ oµ thσ line¼á bu⌠ i≤ doe≤ NO╘ movσ thσ cursor«á Here¼ i⌠ blot≤ ou⌠ ì
thσ curren⌠ valuσ oµ thσ fielΣ whicΦ ha≤ beeε chosen¼á allowinτ thσ use≥ t∩ ì
typσ iε anothe≥ value¼á whicΦ i≤ theε read«á Thσ FormWritσ listinτ ha≤á t∩ ì
modifieΣá s∩á tha⌠ choicσ number≤ arσ addeΣ beforσ eacΦ fielΣ labe∞á - thi≤ ì
give≤á u≤ thσ variou≤ number≤ t∩ choose«á Choicσ 9╣ wil∞ alte≥á thσá fielΣ ì
Deleted¼á whicΦá wa≤á se⌠ t∩ Falsσ a⌠ datß entry¼á t∩ True«á Wheneve≥á thσ ì
inidividua∞á iteφ i≤ listeΣ oε thσ screen¼á thσ strinτ "¬ DELETE─á *óá wil∞ ì
appea≥á a⌠á thσ heaΣ oµ thσ listing¼á t∩ sho≈ tha⌠ thσ iteφ i≤á markeΣá fo≥ ì
deletion« B∙ typinτ 9╣ ß seconΣ time¼ thσ iteφ caε bσ undeleted.
Oncσá thσ editinτ oµ thσ iteφ ha≤ beeε finished¼á wσ mus⌠ rewritσá thσ ì
recorΣ t∩ disk«á Wheε wσ accesseΣ thσ recorΣ witΦ thσ ReaΣ state-ment¼ thσ ì
Filσá Pointe≥ wa≤ moveΣ t∩ poin⌠ t∩ thσ followinτ record«á S∩ tha⌠ wσá caε ì
writσ thσ RecorΣ bacδ t∩ thσ correc⌠ placσ iε thσ file¼ wσ havσ t∩ movσ thσ ì
recorΣ pointe≥ bacδ onσ placσ t∩ poin⌠ t∩ thσ correc⌠ record« Thi≤ i≤ donσ ì
iεá thσ "Seek(PartFile¼á Pointer-1)ó statement«á Thσ valuσ oµ thσá curren⌠ ì
record'≤ pointe≥ wa≤ storeΣ wheε i⌠ wa≤ found¼á beforσ wσ wrotσ i⌠ t∩ disk¼ ì
iε thσ variablσ Pointer«á Wheε thi≤ statemen⌠ i≤ executed¼á thσ pointe≥ i≤ ì
moveΣá agaiε froφ thσ beginninτ oµ thσ filσ t∩ thσ correc⌠ record«á Wσ caε ì
theε writσ thσ recorΣ t∩ thσ filσ witΦ thσ usua∞ Writσ statement.
Iµá wσá wan⌠á t∩ acces≤ anothe≥ record¼á wσ havσá t∩á star⌠á froφá thσ ì
beginninτ oµ thσ filσ again¼á sincσ thσ ne≈ recorΣ ma∙ bσ positioneΣ beforσ ì
thσ currentl∙ accesseΣ record« S∩ wσ havσ t∩ Rese⌠ thσ filσ iε thσ "D∩ yo⌡ ì
wan⌠ another?ó section¼ iµ tha⌠ choicσ i≤ made.
Iεá thσá previou≤á par⌠á oµá thi≤á series¼á wσá talkeΣá abou⌠á passinτ ì
parameter≤á t∩ ß Function«á Thσ actua∞ situatioε oµ paramete≥ passinτ i≤ ß ì
littlσ morσ complicateΣ thaε wha⌠ wσ saiΣ there¼ however.
Wheεá wσ passeΣ thσ paramete≥ oµ thσ FileNamσ iε thσ Functioεá Exists¼ ì
wσá actuall∙ onl∙ madσ ß cop∙ oµ thσ valuσ oµ thσ FileName¼á anΣ workeΣá oε ì
it« Thi≤ i≤ calleΣ ß "valueó paramete≥ - wheε thσ procedurσ i≤ called¼ thσ ì
paramete≥ iε thσ calleΣ procedurσ i≤ initializeΣ t∩ thσ valuσ oµ thσ actua∞ ì
paramete≥ whicΦ correspond≤ t∩ i⌠ iε thσ call«á Thσ actua∞ variablσ iε thσ ì
callinτ statemen⌠ i≤ protecteΣ froφ change.
However¼á wσ ma∙ wan⌠ t∩ manipulatσ thσ actua∞ valuσ itself¼á anΣá no⌠ ì
jus⌠á ß cop∙ oµ it«á Wσ d∩ thi≤ b∙ passinτ t∩ thσ procedurσ thσ Addres≤ oµ ì
thσ valuσ iε memory¼á s∩ tha⌠ thσ procedurσ manipulate≤ i⌠á directly«á Thσ ì
paramete≥á iεá thσ procedurσ heade≥ i≤ theε calleΣ ß "variableóá parameter« ì
I⌠á i≤ formeΣ b∙ writinτ thσ reserveΣ worΣ VA╥ iε fron⌠ oµ thσ variablσá o≥ ì
variable≤ b∙ whicΦ wσ arσ goinτ t∩ manip-ulatσ thσ value.
è Herσ i≤ aε examplσ oµ Variablσ paramete≥ passinτ ¿ takeε froφ thσá T╨ ì
Manual¼á p«á 132«á Thσá Manua∞á ╔á aφá usinτá i≤ tha⌠á fo≥á Versioεá │á oµ ì
TurboPascal.)
Procedure Switch ( Var a, b : Integer );
Var Tmp : Integer;
begin
Tmp := a; a := b; b := Tmp;
end;
áááááááááThσá callinτ statemen⌠ - Switch¿ i,Ω )╗á wil∞ actuall∙ ì
áááááááááswitcΦ thσ value≤ oµ "ió anΣ "j"¼ whicΦ arσ addresseΣ iε ì
áááááááááthσ procedurσ b∙ thσ variablσ label≤ "aó anΣ "b".
ááááááááá BotΦá Function≤ anΣ Procedure≤ caε usσ eithe≥á typσ ì
áááááááááoµ paramete≥ passing¼á anΣ thσ tw∩ type≤ caε bσ mixeΣ iε ì
áááááááááonσ procedurσ o≥ function«á Herσ i≤ aε example¼ usinτ ß ì
áááááááááprocedurσ whicΦ compute≤ thσ intege≥ anΣ factiona∞ part≤ ì
áááááááááoµá ßá number«á (Examplσ froφ "Probleφá Solvinτá .«á iε ì
áááááááááPascal¼áá b∙á Koffman¼á p.170¼á ßá booδá I'vσá mentioneΣ ì
ááááááááábefore.)
áááááProcedure Breakdown ( x : Real;
ááááá Var Frac : Real;
ááááá Var Whole : Integer);
áááááBegin
ááááá Whole := Trunc(x);
ááááá Frac := x - whole
áááááEnd;
This procedure is called by the statement
Breakdown ( a, r, i);
Writeln(a:7:2, r:7:2, i:7);
áááááááááwherσ "aó i≤ ß rea∞ number¼á whosσ valuσ i≤ passeΣá int∩ ì
ááááááááá"xóá ("aóá itselµá i≤ no⌠ changeΣ b∙á thσá procedurσá )╗ ì
ááááááááá"Fracó anΣ "Wholeó actuall∙ manipulatσ thσ variable≤ "ró ì
ááááááááá(ßá real⌐ anΣ "ió (aε integer)¼á anΣ s∩ havσ thσ VA╥á iε ì
áááááááááfron⌠ oµ theφ iε thσ paramete≥ string.
ááááááááá Iµá "aóá haΣá thσá valuσ 1.2│á wheεá Breakdowεá wa≤ ì
ááááááááácalled¼ thσ Writelε statemen⌠ woulΣ producσ thσ resul⌠ - ì
ááááááááá1.2│ 0.2│ 1
ááááááááá
ááááááááá"róá anΣá "ió receivσ thei≥ value≤ froφá thσá procedure¼ ì
ááááááááárathe≥ thaε iε thσ callinτ program« Thσ value≤ computeΣ ì
áááááááááiεá thσ procedurσ arσ addres-seΣ b∙ theφ - the∙ arσá no⌠ ì
ááááááááácopie≤ oµ thσ procedurσ values.
ááááááááá Valuσá parameter≤ ¿ n∩ Va≥ ⌐ arσ one-wa∙á channels¼ ì
áááááááááfroφ cal∞ t∩ procedurσ o≥ function« Variablσ parameter≤ ì
ááááááááá¿ witΦ VA╥ ⌐ arσ two-wa∙ communicatioε channels.
Therσá i≤ mucΦ morσ t∩ learε iε Pascal¼á bu⌠ yo⌡ caε g∩ oε froφá here¼ ì
I'φ sure« Koffman'≤ book≤ wil∞ bσ ß grea⌠ hel≡ t∩ you« Oncσ you'vσ learn⌠ ì
Pascal¼á you'l∞ finΣ i⌠ ß better¼á albei⌠ ß longer¼ wa∙ oµ programminτ thaε ì
programminτ iε Basic.è