home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug003.arc
/
PASCAL.009
< prev
next >
Wrap
Text File
|
1979-12-31
|
7KB
|
175 lines
PASCAL FOR BASIC PROGRAMMERS
Dixon Kenney
PART IX.
We'rσá no≈á goinτ t∩ adΣ t∩ ou≥ Inventor∙ Prograφ thσ procedurσá whicΦ ì
wil∞ finΣ an∙ onσ item«á Thi≤ procedurσ find≤ aε iteφ b∙ it≤ par⌠á number╗ ì
i⌠á coulΣá bσ rewritteε o≥ extendeΣ t∩ finΣ aε iteφá b∙á description¼á o≥ ì
whateve≥ fielΣ yo⌡ required« Here'≤ thσ codσ -
ááááProcedurσ Finditem;
ááááConst
áááá Heade≥ ╜ º ¬ FIN─ A╬ EXISTIN╟ ITE═ O╞ STOC╦ ¬ ';
ááááVar
áááá P╬ ║ Integer;
áááá YesN∩ ║ Char;
áááá Agaiε ║ Boolean;
áááá FounΣ ║ Boolean;
ááááBegin
áááá Assign(PartFile¼ FileName);
áááá Reset(PartFile);
áááá Agaiε :╜ True;
áááá Repeat
áááá ClrScr;
áááá Writeln¿ º ':20¼ Header);
áááá Writeln╗ Writeln;
áááá Write('Ente≥ thσ Par⌠ Numbe≥ oµ thσ Iteφ requireΣ ║ ');
áááá Readln(PN);
áááá WitΦ Par⌠ do
áááá Begin
áááá FounΣ :╜ False;
áááá Whilσ no⌠ EOF(PartFile⌐ anΣ no⌠ FounΣ do
áááá Begin
áááá Read(PartFile,Part);
áááá Iµ PartNuφ ╜ P╬ then
áááá FounΣ :╜ True;
áááá End;
áááá Iµ no⌠ FounΣ then
áááá Begin
áááá Writeln╗ Writeln;
áááá Write('Thi≤ iteφ doe≤ no⌠ exis⌠ ');
áááá End
áááá Else
áááá Begin
áááá Formwrite(Header);
áááá Iµ DeleteΣ then
áááá Begin
áááá GoToXY(10,2);
áááá Write('¬ DELETE─ *');èáááá End╗ √ oµ Iµ DeleteΣ }
áááá 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);
áááá End╗ √ oµ Elsσ .« }
áááá End;
áááá Writeln╗ Writeln;
áááá Write('D∩ yo⌡ wan⌠ t∩ looδ fo≥ anothe≥ par⌠ █ Y/╬ ▌ ┐ ');
áááá Read(YesNo);
áááá Iµ UpCase(YesNo)╜ 'Y'
áááá Then
áááá Begin
áááá Agaiε :╜ True;
áááá Reset(PartFile)
áááá End
áááá Else
áááá Agaiε :╜ False
áááá Unti∞ Agaiε ╜ False;
áááá Close(PartFile)
ááááEnd╗ √ Procedurσ FindIteφ )
Comments on the code -
Ou≥ majo≥ probleφ t∩ addres≤ i≤ thi≤ - wha⌠ happen≤ iµ thσ iteφ i≤ no⌠ ì
iε thσ datß list« Wσ coulΣ havσ writteε thσ codσ t∩ finΣ i⌠ likσ thi≤ -
áááááááááRepeat Read(PartFile) Until PartNum = PN;
However¼á iµ thσ iteφ i≤ no⌠ oε thσ list¼á thi≤ codσ wil∞ causσ thσ ì
prograφ t∩ "bomΓ outó witΦ ß run-timσ erro≥ ¿ I'vσ trieΣ it¼ s∩ ╔ kno≈ tha⌠ ì
thi≤ wil∞ happeε !⌐ S∩ wσ se⌠ tw∩ condition≤ -
i⌐á ReaΣá unti∞á thσ enΣ oµ thσ Filσ - Whilσá no⌠á EOF(filevariable⌐ ì
mean≤á tha⌠á eacΦá recorΣ wil∞ bσ reaΣ iε turεá unti∞á thσá recorΣá pointe≥ ì
reache≤ thσ EO╞ marker╗á thσ ReaΣ functioε wil∞ end¼ withou⌠ goinτ pas⌠ thσ ì
marker;
ii⌐ ReaΣ thσ filσ unti∞ thσ iteφ requireΣ i≤ found« Wσ se⌠ ß Booleaε ì
variablσ FOUN─ equa∞ t∩ FALS┼ wheε wσ ente≥ thσ loo≡ - i⌠ i≤ FALS┼ tha⌠ thσ ì
iteφ ha≤ beeε FOUND« Iµ wσ finΣ thσ item¼ thσ se⌠ thσ variablσ t∩ TRUE.
Thσá tw∩ condition≤ meaε tha⌠ thσ ReaΣ wil∞ continuσ whilσ i⌠ i≤á TRU┼ ì
botΦá tha⌠á wσ haven'⌠ reacheΣ thσ EnΣ oµ thσ Filσ anΣ als∩ thσ iteφá isn'⌠ ì
FounΣ ¿ NO╘ FOUN─ mean≤ tha⌠ FOUN─ i≤ FALS┼ )« However¼ a≤ sooε onσ oµ thσ ì
condition≤ become≤ TRU┼ - tha⌠ is¼á NO╘ EO╞ o≥ NO╘ FOUN─ becomσ eithe≥á EO╞ ì
o≥ FOUND¼ theε thσ ReaΣ loo≡ wil∞ terminatσ correctly.
Iµ thσ flaτ FOUN─ remain≤ FALS┼ wheε thσ EO╞ i≤ reached¼á theε wσ havσ ì
t∩á sa∙ tha⌠ thσ iteφ doesn'⌠ exis⌠ - whicΦ i≤ carrieΣ ou⌠ b∙ thσ I╞á blocδ ì
oµ thσ I╞ NO╘ FOUN─ par⌠ oµ thσ code« Iµ FOUN─ i≤ se⌠ t∩ TRUE¼ theε wσ caε ì
writσá ou⌠á thσá detail≤ oε t∩ thσ screeε - thσ ELS┼ par⌠ oµ thσá I╞á FOUN─ ì
block.è In this block, notice the statement
If Deleted
Thσá fielΣ DELETE─ i≤ ß Booleaε fielΣ - i⌠ caε havσ eithe≥á oµá thσ ì
value≤ TRU┼ o≥ FALSE« Thσ wa∙ t∩ se⌠ ß conditioε oε ß Booleaε fielΣ i≤ thσ ì
wa∙ wσ havσ writteε it.
If Deleted means if the field Deleted is set to TRUE
If NOT Deleted means if the field Deleted is set to FALSE
Wσ don'⌠ havσ t∩ usσ thσ "=ó o≥ "<>ó sign≤ witΦ Booleaε variables.
Towards the end of the procedure, we have the function
UpCase(YesNo)
Thi≤ functioε take≤ an∙ alphabetiπ character≤ iε thσ variable¼á anΣ ì
treat≤á theφá al∞á a≤ iµ the∙ werσ Uppe≥ Casσ characters«á Iεá ßá previou≤ ì
procedure¼ wσ useΣ thσ phrase
If variable in [ 'Y', 'y' ]
This is an alternative way of doing the same thing.
Wheε wσ wrotσ thσ functioε EXISTS¼á wσ passeΣ ß valuσ t∩á it¼á througΦ ì
thσ paramete≥ º (Namσ ║á Filespec⌐ ║ Booleaε '« Wσ caε diagraφ it≤ workinτ ì
likσ thi≤ -
|------------------------|
If Exists(FileName) |v
|^ Function Exists (Name : Filename ) : Boolean;
| Begin
| Exists := (IOResult = 0)
|---------------------|
Wheε thσ functioε i≤ invoked¼ TurboPasca∞ make≤ ß copyô oµ thσ content≤ ì
oµá thσ operanΣ oµ thσ functioε (FileName)¼á whicΦ i≤ useΣ b∙ thσá variablσ ì
Namσ iε thσ Functioε itself«á Wheneve≥ thσ functioε i≤ called¼ thσ datß i⌠ ì
use≤á caεá bσ differen⌠ eacΦ timσ - thσ actua∞ valuσ i≤ substituteΣ iεá thσ ì
functioεá call«á Noticσá tha⌠á thσ variablσ i≤ declareΣá iεá thσá functioε ì
'titleºá - thi≤ i≤ calleΣ ß "forma∞ paramete≥ list"¼á anΣ thσ variable≤á d∩ ì
no⌠ neeΣ t∩ bσ declareΣ iε thσ usua∞ way« A⌠ thσ enΣ oµ thσ paramete≥ lis⌠ ì
i≤á thσ typσ oµ thσ resul⌠ thσ functioε use≤ - iε thi≤ casσ ß Booleaε ¿á i≤ ì
i⌠á TRU┼ tha⌠ thσ filσ exists¼á o≥ FALS┼ )«á Al∞ variable≤ declareΣá iεá ß ì
functioεá o≥á procedurσ arσ LOCA╠ t∩ tha⌠ block╗á tha⌠ is¼á the∙ canno⌠á bσ ì
accesseΣ b∙ an∙ othe≥ blocδ iε thσ program¼á unles≤ i⌠ i≤ calleΣ froφ ¿ anΣ ì
therefore¼ iε somσ wa∙ "nesteΣ in"⌐ thi≤ block« So¼ iε Functioε Exists¼ a≤ ì
sooε a≤ thσ functioε i≤ exited¼á thσ memor∙ useΣ b∙ thσ variablσ ╞ whicΦ wσ ì
havσá declareΣá here¼á a≤ wel∞ a≤ Namσ iε thσá forma∞á paramete≥á list¼á i≤ ì
releaseΣ b∙ thσ compiler¼ anΣ i≤ availablσ fo≥ useΣ again«
Thi≤á als∩á mean≤ that¼á iµ wσ havσ ß variablσ labelleΣ ╪ iε thσá maiε ì
program¼ ß variablσ labelleΣ ╪ caε als∩ bσ declareΣ here¼ a≤ i⌠ exist≤ iε ß ì
differen⌠ par⌠ oµ memory.
Iε thσ nex⌠ part¼á wσ wil∞ talδ abou⌠ Paramete≥ passinτ t∩ Procedures¼ ì
whicΦ i≤ aε extensioε oµ wha⌠ wσ havσ talkeΣ abou⌠ here«
END OF PART NINE.è