home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug003.arc
/
PASCAL.007
< prev
next >
Wrap
Text File
|
1979-12-31
|
9KB
|
226 lines
PASCAL FOR BASIC PROGRAMMERS
Dixon Kenney
PART VII
Iε thi≤ nex⌠ par⌠ iε thσ serie≤ oµ programminτ iε Pascal¼ wσ arσ goinτ ì
t∩ writσ ß procedurσ b∙ whicΦ wσ caε adΣ aε iteφ oµ stocδ ¿ tha⌠ is¼ ß datß ì
recorΣ ⌐ t∩ thσ datß file«á Iε doinτ this¼á wσ arσ goinτ t∩ usσ ß mask¼ s∩ ì
tha⌠á thσ operato≥ wh∩ i≤ fillinτ iε thσ informatioε wil∞ kno≈ exactl∙ wha⌠ ì
informatioε wσ wan⌠ theφ t∩ typσ in«á Mos⌠ oµ thσ prograφ i≤ lef⌠ out¼á a≤ ì
i⌠á doesn'⌠á diffe≥á froφá thosσ iε previou≤á part≤á oµá thσá series«á Thσ ì
function≤ anΣ procedure≤ wσ havσ useΣ beforσ arσ indicateΣ b∙ thei≥ Includσ ì
calls«á Thσ linσ number¼ therefore¼ arσ no⌠ mean⌠ t∩ refe≥ t∩ thσ wholσ oµ ì
thσ program« The∙ arσ therσ simpl∙ fo≥ referencσ iε thσ text.
1áá Prograφ Inventory_3;
3áááType
4ááá St3░ ╜ String[30];
6áááVar
áá7ááá Heade≥ ║ St30;
10ááá{$╔ EXISTS.FN├ }
12ááá{$╔ CREATEFL.PR╧ }
14 {$╔ FWRITE.PR╧ }
16 ááProcedurσ FormWritσ ¿ ╚ ║ St3░ );
18áááConst
á19ááá TabΓ ╜ º ';
21áááBegin
23ááá ClrScr;
á24ááá Write(º ':25);
á25ááá Writeln(H);
á26ááá Writeln╗ Writeln;
á27ááá Writeln(Tabb¼ 'Par⌠ Numbe≥ ║ ');
á28ááá Writeln(Tabb¼ 'Descriptioε ║ ');
á29ááá Writeln;
á30ááá Writeln(Tabb¼ 'Cos⌠ t∩ u≤ ║ ');
á31ááá Writeln(Tabb¼ 'Retai∞ Pricσ ║ ');
á32ááá Writeln;
á33ááá Writeln(Tabb¼ 'Minimuφ Leve∞ ║ ');
á34ááá Writeln(Tabb¼ 'Maximuφ Leve∞ ║ ');
á35ááá Writeln;
á36ááá Writeln(Tabb¼ 'Oε HanΣ No≈ ║ ');
38áááEnd╗ √ Procedurσ FormWritσ }
41 {$╔ NEWITEM.PR╧ }
è 43áááProcedurσ NewItem;
á45áááConst
á46 áá Heade≥ ╜ º ¬ AD─ ENTR┘ T╧ MASTE╥ FIL┼ *';
á48áááVar
á49ááá Agaiε ║ Boolean;
á50ááá YesN∩ ║ Char;
á52áááBegin
á54ááá Agaiε :╜ True;
á56ááá Assign(PartFile¼ FileName);
á57ááá Reset(PartFile);
á58ááá Seek(PartFile¼ FileSize(PartFile));
á60ááá Repeat
á61ááá FormWrite(Header);
á62ááá WitΦ Par⌠ do
á63ááá Begin
á64ááá GoToXY(32¼ 4)╗ Read(PartNum);
á65ááá GoToXY(32¼ 5)╗ Read(Description);
á66ááá GoToXY(32¼ 7)╗ Read(Cost);
á67ááá GoToXY(32¼ 8)╗ Read(Retail);
á68ááá GoToXY(32,10)╗ Read(MinOH);
á69ááá GoToXY(32,11)╗ Read(MaxReorder);
á70ááá GoTOXY(32,13)╗ Read(CurrentOH);
á71 áá Write(PartFile¼ Part)
á72ááá End;
á74ááá Writeln╗ Writeln;
á75ááá Write('D∩ yo⌡ havσ anothe≥ par⌠ t∩ ente≥ [Y/N▌ ┐ ');
á76ááá Read(YesNo);
á77ááá Iµ YesN∩ iε █ 'Y'¼ 'y']
á78ááá theε Agaiε :╜ True
á79ááá Else
á80ááá Agaiε :╜ False
á81ááá Unti∞ Agaiε ╜ False;
á83ááá Close(PartFile)
á85áááEnd╗ √ Procedurσ NewIteφ }
87 {$╔ MENU.PR╧ }
á89áááBegin { Main Section of the program }
á91ááá Casσ Iteφ of
á92ááá 1║ NewItem;
á94áááEnd.
Therσá arσ onσ o≥ tw∩ necessar∙ extrß declarations╗á wσ havσá onl∙á t∩ ì
dea∞á witΦá thσ materia∞ iε thσ tw∩ ne≈ procedures«á Let'≤ dea∞á witΦá thσ ì
procedurσ FormWritσ first.
è Thi≤á procedurσá exist≤ simpl∙ t∩ writσ ß datß masδ oε thσá screen«á ┴ ì
masδá i≤ ß screeε whicΦ describe≤ thσ recorΣ iε word≤ whicΦá thσá oper-ato≥ ì
caεá understand«á "MinOHó migh⌠ bσ understooΣ b∙ thσ persoε wh∩ wrotσá thσ ì
code¼á bu⌠á ß use≥ oµ thσ prograφ woulΣ understanΣ "Minimuφ Leveló ß littlσ ì
morσá easily«á Thσá detail≤á oµá eacΦ fielΣá oµá thσá recorΣá arσá printeΣ ì
sequentiall∙ oε thσ screen.
Iεá linσá 16¼á thσá procedurσ header¼á ß paramete≥ i≤á passeΣá t∩á thσ ì
procedure« I⌠ i≤ thσ Heade≥ fo≥ thσ screeε mask« Thi≤ particula≥ masδ caε ì
bσá useΣá fo≥ morσ thaε th≤ procedure¼á sincσ i⌠ describe≤ eacΦá recorΣá iε ì
full«á So¼á wσá pas≤ t∩ thσ procedurσ whicΦ use≤ thσ masδ thσ titlσ oµ thσ ì
mask¼á whicΦ i≤ se⌠ u≡ iε thσ callinτ procedure¼á herσ linσ 46« B∙ passinτ ì
thi≤ header¼á mucΦ codσ writinτ i≤ saved¼á sincσ wσ d∩ no⌠ neeΣ t∩ writσá ß ì
masδ fo≥ eacΦ individua∞ procedure.
No≈á let'≤ movσ oε t∩ thσ nex⌠ procedurσ - Procedurσá NewItem«á Therσ ì
arσ ß numbe≥ oµ item≤ t∩ looδ a⌠ here«á Thi≤ procedurσ i≤ calleΣ froφ linσ ì
92¼ whicΦ i≤ par⌠ oµ thσ Casσ statemen⌠ iε thσ Maiε blocδ oµ thσ program.
Iε linσ 57¼ thσ filσ whicΦ ha≤ beeε previousl∙ createΣ i≤ opened« Thσ ì
functioεá Rese⌠á open≤á aε alread∙ createΣ file«á Herσ i⌠ open≤á thσá filσ ì
referreΣ t∩ b∙ thσ filσ variablσ PartFile¼ tha⌠ is¼ "INVENT.DAT"« Wheε thσ ì
filσ i≤ opened¼á thσ recorΣ pointe≥ i≤ se⌠ t∩ poin⌠ a⌠ thσ beginninτ oµ thσ ì
file¼á tha⌠ is¼ t∩ recorΣ 0« Thσ filσ i≤ closeΣ iε linσ 83¼ usinτ thσ samσ ì
functioε a≤ wσ useΣ iε thσ CreateFilσ proced-urσ - Close« Iε betweeε thesσ ì
tw∩ functions¼ wσ d∩ ß lo⌠ oµ work.
Iε linσ 58¼á wσ pu⌠ thσ recorΣ pointe≥ t∩ thσ enΣ oµ thσá file«á Thi≤ ì
linσá contain≤ tw∩ functions«á Thσ functioε Seek(filevariable,n)ô move≤ thσ ì
recorΣá pointe≥ througΦ thσ filσ 'filevariableº unti∞ i⌠ point≤á a⌠á recorΣ ì
numbe≥á 'n'«á Thi≤ functioε caε bσ useΣ a⌠ an∙ timσ t∩ acces≤ ß particula≥ ì
recorΣ iµ thσ numbe≥ oµ thσ recorΣ i≤ known.
Iεá orde≥ t∩ appenΣ ß recorΣ t∩ thσ file¼á wσ mus⌠ movσ t∩ thσ enΣá oµ ì
thσ filσ - tha⌠ is¼á t∩ thσ recorΣ nex⌠ pas⌠ thσ fina∞ recorΣ oµ thσá file« ì
Thi≤á i≤ donσ b∙ usinτ thσ functioε FileSize(filevariable)«á Thi≤ functioε ì
count≤ thσ numbe≥ oµ record≤ iε thσ file«á So¼á iµ wσ haΣ ╕á records¼á thσ ì
functioε return≤ thσ numbe≥ 8« However¼ sincσ thσ firs⌠ recorΣ i≤ numbereΣ ì
0¼ thσ fina∞ actua∞ recorΣ i≤ numbe≥ 7¼ anΣ thσ Seeδ functioε i≤ positioneΣ ì
t∩á poin⌠á t∩ thσ nex⌠ recorΣ t∩ bσ appendeΣ t∩ thσ file«á Notσ tha⌠á thi≤ ì
functioε i≤ oµ typσ integer¼á anΣ thσ numbe≥ 'nº supplieΣ t∩ Seeδ mus⌠ als∩ ì
bσ oµ typσ Integer.
No≈ looδ a⌠ linσ 6▓ - WIT╚ Par⌠ DO«á Wheε wσ wan⌠ t∩ acces≤ ß record¼ ì
wσá caε finΣ ourselve≤ iε ß bi⌠ oµ trouble¼á a≤ wσ usuall∙ wan⌠ t∩ worδá oε ì
thσ individua∞ field≤ oµ eacΦ record«á Iε Pascal¼ wσ caε referencσ eacΦ oµ ì
thσ field≤ oµ ß record≤ b∙ usinτ ß fielΣ selector«á Thi≤ fielΣ selecto≥ i≤ ì
madσ u≡ oµ thσ recorΣ namσ followeΣ b∙ ß perioΣ followeΣ b∙ thσ fielΣ name« ì
S∩ here¼ t∩ acces≤ eacΦ field¼ wσ woulΣ havσ t∩ say¼ fo≥ example
Part.Partnuφ Part.Retai∞ Part.CurrentOH
I⌠á woulΣ bσ mucΦ easie≥ fo≥ u≤ iµ wσ werσ ablσ t∩ acces≤á eacΦá fielΣ ì
simpl∙á b∙ it≤ owε label¼á withou⌠ thσ neeΣ fo≥ thσ prefixeΣ recorΣá label« ì
Wσ caε makσ thing≤ mucΦ shorte≥ b∙ usinτ thi≤ WIT╚ statement¼ a≤ yo⌡ seσ i⌠ ì
useΣ here« Thσ synta° i≤ quitσ simplσ -
WIT╚ record_variable_labe∞ D╧ statement.
è Thσ 'statementº par⌠ i≤ wha⌠ yo⌡ wan⌠ t∩ d∩ witΦ thσ individua∞ field≤ ì
oµá thσá recorΣá yo⌡á arσ accessing«á I⌠ ma∙ bσ a≤á simplσá o≥á comple°á ß ì
statemen⌠á a≤á yo⌡ wish«á Thσ WIT╚ statemen⌠ caε bσ mucΦ morσá complicateΣ ì
thaεá thi≤ - you≥ Turb∩ Pasca∞ manua∞ wil∞ sho≈ yo⌡ ho≈ iµ yo⌡á arσá reall∙ ì
interested¼ bu⌠ thi≤ i≤ complicateΣ enougΦ fo≥ u≤ now.
Iεá line≤ 64µ (anΣ iε linσ 14╩ oµ thσ previou≤ prograφ iε par⌠ VI⌐á wσ ì
havσ ß simplσ curso≥ positioninτ statement.
áááááááááThi≤á i≤á equivalen⌠á t∩á MicroWorlΣá Basic'≤á CUR╙ ì
ááááááááástatement¼ anΣ i≤ useΣ iε mucΦ thσ samσ way¼ a≤ yo⌡ ì
ááááááááácan see.
Thσ curso≥ i≤ moveΣ t∩ thσ positioε oε thσ screeε indicateΣ b∙ thσ tw∩ ì
intege≥á number≤ oε whicΦ thσ functioε operates«á Thσ firs⌠ i≤ thσá columε ì
number¼á anΣ thσ seconΣ thσ row« NB« Thi≤ i≤ thσ reversσ oµ thσ situatioε ì
a≤ describeΣ iε thσ Manual¼ whicΦ say≤ thσ functioε i≤ row¼ column«
Iε thi≤ function¼á thσ curso≥ i≤ positioneΣ iε turε a⌠ thσ enΣ oµ eacΦ ì
oµá thσá prompt≤á printeΣ oε thσ screeε b∙ thσ mask«á Thi≤á prevent≤á botΦ ì
scrollinτ oµ thσ screeε anΣ overwritinτ oµ informatioε oε it.
Iε linσ 71¼á afte≥ al∞ thσ informatioε i≤ obtained¼á wσ actuall∙ writσ ì
thσáá recorΣá t∩á disk¼áá usinτá thσá thσáá procedurσáá WRITE(filevariable¼ ì
recordvariable)«á Thi≤ functioε differ≤ froφ mos⌠ othe≥ Pascals¼ whicΦ usσ ì
thσ procedurσ PUT« Iµ yo⌡ arσ writinτ iε anothe≥ versioε oµ Pascal¼ havinτ ì
learn⌠ TPascal¼á theε bσ ver∙ carefu∞ oµ this¼á anΣ finΣ ou⌠ jus⌠ wha⌠ you≥ ì
ne≈ version'≤ synta° is.
Finally¼á wσ comσ t∩ thσ concep⌠ oµ ß set¼á iε linσ 77« Iε Pascal¼ wσ ì
arσá ablσá t∩ definσ sets¼á whicΦ thσ manua∞ describe≤ a≤ "collect-ion≤á oµ ì
relateΣá object≤ whicΦ ma∙ bσ though⌠ oµ a≤ ß whole.ó Thσ member≤á oµá thσ ì
se⌠ ¿ eacΦ oµ it≤ individua∞ item≤ ⌐ mus⌠ bσ oµ thσ samσ type¼ whicΦ caε bσ ì
an∙ scala≥ typσ excep⌠ typσ REAL.
Herσá wσ simpl∙ writσ ß conditiona∞ statement¼á t∩ seσ iµ thσ content≤ ì
oµ ß variablσ exis⌠ withiε ß set«á Noticσ tha⌠ thσ member≤ oµ thσ se⌠á arσ ì
defineΣ betweeε squarσ brackets¼ eacΦ separateΣ froφ thσ other≤ b∙ ß comma¼ ì
and¼á iε thσ casσ oµ characters¼ delimiteΣ b∙ singlσ quotσ marks« ┴ rangσ ì
oµá se⌠á member≤á caεá bσ expresseΣ b∙ separatinτ thσá lowes⌠á anΣá highes⌠ ì
element≤ oµ thσ rangσ b∙ tw∩ consecutivσ periods¼ likσ thi≤ -
[ 'A'..'Z' , 'a'..'z' , '0'..'9' ]
Iε thi≤ line¼ wσ arσ writinτ ß mucΦ simple≥ wa∙ oµ saying
If YesNo = 'Y' or YesNo = 'y'
Yo⌡ caε seσ ho≈ mucΦ spacσ i≤ saveΣ iε ou≥ codσ iµ therσ arσ morσ thaε ì
tw∩ element≤ iε thσ se⌠ beinτ tested«
END OF PART SEVEN.