home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug001.arc
/
PART10.IQS
/
PART10.INS
Wrap
Text File
|
1979-12-31
|
14KB
|
392 lines
.po0
dBAS┼ I╔ PAR╘ 10
Appendinτ record≤ t∩ ß databasσ usinτ dBasσ 2.│ appendinτ techniquσ i≤ ì
actuall∙ morσ comple° thaε editinτ existinτ records¼ a≤ wσ shal∞ see« WitΦ ì
dBasσ 2.┤ i⌠ i≤ particularl∙ easy╗ jus⌠ desigε ß screeε forma⌠ fielΣ anΣ theε ì
writσ iε you≥ code.
¬ EDI╘ ┴ RECORD
SE╘ FORMA╘ T╧ EDIT
EDI╘ RECOR─ #
Oµ coursσ i⌠ wil∞ onl∙ worδ iε dBasσ 2.┤ o≥ later¼ anΣ theε onl∙ iµ yo⌡ ì
jus⌠ wan⌠ t∩ edi⌠ field≤ a≤ the∙ arσ entereΣ iε thσ database« However¼ quitσ ì
ofteε yo⌡ wan⌠ t∩ maintaiε field≤ iε thσ databasσ iε ß forma⌠ whicΦ woulΣ ì
bafflσ thσ enΣ user¼ o≥ woulΣ bσ inconvenien⌠ t∩ dea∞ with« Takσ date≤ fo≥ ì
example.
DAT┼ DISORDER
Date≤ arσ particularl∙ inconvenien⌠ t∩ dea∞ with¼ especiall∙ iµ yo⌡ wan⌠ ì
t∩ sor⌠ o≥ inde° oε them« Sortinτ assume≤ tha⌠ thσ mos⌠ significan⌠ character≤ ì
iε ß valuσ arσ a⌠ thσ lef⌠ hanΣ end¼ anΣ tha⌠ decreasingl∙ significan⌠ ì
character≤ liσ acros≤ t∩ thσ right« Iε Australia¼ wσ jus⌠ don'⌠ handlσ date≤ ì
tha⌠ way╗ insteaΣ wσ pu⌠ theφ iε thσ forma⌠ dd/mm/yy/¼ s∩ thσ mos⌠ significan⌠ ì
character≤ arσ thσ 7tΦ anΣ 8th¼ thσ next¼ thσ 4tΦ anΣ 5th¼ anΣ thσ character≤ ì
oµ leas⌠ significancσ arσ thσ 1s⌠ anΣ 2nΣ witΦ thσ exceptancσ oµ thσ slashe≤ ì
whicΦ havσ n∩ significancσ a⌠ all.
Iε thσ U.S« thσ thσ situatioε i≤ similar¼ witΦ aε eveε les≤ logica∞ datσ ì
format║ mm/dd/yy« Wh∙ can'⌠ wσ bσ morσ logica∞ likσ thσ Sweeds¼ wh∩ (╔ ì
believe⌐ writσ date≤ iε thσ forma⌠ yy/mm/dd?
Clearl∙ iµ wσ wan⌠ t∩ inde° o≥ sor⌠ oε dates¼ wσ mus⌠ reforma⌠ theφ ì
beforσ writinτ theφ int∩ thσ database¼ s∩ the∙ arσ followinτ rule≤ oµ ì
significancσ fo≥ sorting« Thi≤ caε bσ donσ b∙ forcinτ thσ use≥ t∩ ente≥ thσ ì
datσ witΦ thσ digit≤ iε aε appropriatσ positioε usinτ thσ @..GET..PICTUR┼ ì
statement« Thi≤ operate≤ ß bi⌠ likσ thσ BASI├ PRIN╘ USIN╟ statement¼ excep⌠ iε ì
reverse« Iµ wσ sa∙ iε ou≥ code:
└ 2,6░ GE╘ disdatσ USIN╟ '99/99/99'
dBasσ wil∞ displa∙ tha⌠ fielΣ witΦ ß couplσ oµ slashe≤ alread∙ iε it¼ ì
whicΦ thσ use≥ canno⌠ overtypσ o≥ move« Thu≤ thσ use≥ i≤ forceΣ t∩ inpu⌠ thσ ì
datσ iε thσ righ⌠ format« ┴ datσ likσ 6/1/8┤ ha≤ t∩ bσ entereΣ a≤ :
<space╛ ╢ <space╛ ▒ 84
or
╢ <space╛ ▒ <space╛ 84
witΦ thσ firs⌠ forma⌠ beinτ thσ bes⌠ one« Furthermore¼ thσ '9º character≤ iε ì
thσ PICTUR┼ statemen⌠ indicatσ tha⌠ onl∙ numeriπ inpu⌠ wil∞ bσ accepted¼ s∩ ì
thσ use≥ canno⌠ typσ '╢ Jaε 84'« Havinτ go⌠ ou≥ inpu⌠ witΦ thσ character≤ iε ì
thσ righ⌠ places¼ wσ caε reforma⌠ i⌠ t∩ allo≈ indexing« Thσ neates⌠ wa∙ t∩ d∩ ì
thi≤ i≤ witΦ ß simplσ one-liner:
è STOR┼ $(disdate,7,2)+$(disdate,4,2)+$(disdate,1,2⌐ T╧ mdate
whicΦ wil∞ turε thσ 'displa∙ formatº datσ iε disdatσ int∩ ß characte≥ strinτ ì
iε thσ forma⌠ yymmdΣ iε mdate« Thi≤ use≤ thσ '$º substrinτ extractioε operato≥ ì
t∩ picδ ou⌠ tw∩ character≤ a⌠ ß time¼ startinτ a⌠ positioε 7¼ ┤ anΣ ▒ ì
respectivel∙ oµ thσ disdatσ string« Becausσ thi≤ i≤ ß bi⌠ tediou≤ t∩ typσ anΣ ì
havinτ ß distinc⌠ possibilit∙ oµ havinτ typinτ errors¼ ╔ usuall∙ turε i⌠ int∩ ì
ß macro:
STOR┼ 'STOR┼ $(disdate,7,2)+$(disdate,4,2)+$(disdate,1,2⌐ T╧ mdateº T╧ ì
makedate
anΣ theε cal∞ i⌠ a≤ requireΣ iε programs:
&makedate
Oµ course¼ thi≤ approacΦ mean≤ thσ variablσ 'makedateº mus⌠ bσ carefull∙ ì
preserveΣ thorougΦ al∞ thσ release≤ anΣ restore≤ iε thσ sui⌠ oµ programs¼ bu⌠ ì
that'≤ no⌠ terribl∙ difficult.
A╙ YO╒ LIK┼ IT
┴ morσ difficul⌠ probleφ i≤ allowinτ thσ use≥ morσ freedoφ t∩ typσ iε thσ ì
datσ exactl∙ a≤ he/shσ want≤ to« Wσ mus⌠ worδ ou⌠ froφ thσ positioε oµ thσ ì
slashe≤ iε thσ date≤ whicΦ character≤ represen⌠ thσ years¼ month≤ anΣ days« ì
Listinτ ▒ i≤ ß samplσ routinσ t∩ d∩ this« It'≤ inpu⌠ i≤ ß characte≥ string¼ ì
mdate¼ anΣ it'≤ outpu⌠ i≤ threσ numeriπ variables║ day¼ montΦ anΣ year« Thi≤ ì
caε theε bσ useΣ t∩ calculatσ ß Juliaε Calenda≥ number.
It'≤ operatioε i≤ ß littlσ obtusσ iε parts¼ particularl∙ wherσ wσ adΣ thσ ì
positioε oµ thσ firs⌠ slasΦ t∩ thσ positioε oµ thσ seconΣ slash« Thσ fo≥ thi≤ ì
is¼ a⌠ tha⌠ poin⌠ iε thσ program¼ slash▓ contain≤ thσ positioε oµ thσ seconΣ ì
slasΦ iε thσ substrinτ startinτ jus⌠ afte≥ thσ firs⌠ slash¼ wherea≤ wσ wan⌠ ì
it≤ positioε iε thσ origina∞ string¼ iµ yo⌡ seσ wha⌠ ╔ mean« Iµ yo⌡ don't¼ tr∙ ì
single-steppinτ thorougΦ thσ routinσ witΦ ECH╧ se⌠ O╬ anΣ TAL╦ se⌠ ON¼ anΣ al∞ ì
shoulΣ (eventually⌐ becomσ clear.
NAM┼ GAME
┴ simila≥ probleφ i≤ handlinτ names« Generall∙ wσ wan⌠ t∩ inde° ß ì
databasσ containinτ name≤ anΣ addresse≤ oε thσ surnamσ field¼ bu⌠ tha⌠ ì
generall∙ mean≤ tha⌠ wσ havσ t∩ desigε screen≤ witΦ separatσ surnamσ anΣ ì
forenamσ fields¼ anΣ thσ use≥ ha≤ t∩ bσ awarσ oµ wh∙ thi≤ i≤ so« Wh∙ can'⌠ thσ ì
machinσ d∩ thσ dirt∙ work┐ Iε othe≥ words¼ wh∙ can'⌠ thσ use≥ typσ iε ß namσ ì
iε thσ forφ oµ "Mr« Johε Q« Publicó anΣ le⌠ thσ compute≥ worδ ou⌠ wha⌠ thσ ì
variou≤ field≤ are?
Thσ routinσ iε listinτ ▓ i≤ a≤ closσ a≤ I'vσ beeε ablσ t∩ ge⌠ t∩ doinτ ì
this« I⌠ stil∞ impose≤ somσ forma⌠ restriction≤ oε thσ use≥ ie║ middlσ ì
initial≤ mus⌠ alway≤ bσ followeΣ b∙ ß perioΣ (a≤ tha⌠ i≤ ho≈ thσ prograφ ì
recognise≤ them)¼ anΣ thσ titlσ a⌠ thσ beginninτ mus⌠ bσ followeΣ b∙ ß spacσ ì
o≥ ß period« Thσ techniquσ useΣ herσ i≤ t∩ examinσ thσ firs⌠ par⌠ oµ thσ ì
string╗ and¼ a≤ wσ recognisσ wha⌠ i⌠ is¼ t∩ storσ i⌠ iε thσ databasσ usinτ ß ì
REPLAC┼ command╗ anΣ "lo≡ i⌠ offó thσ fron⌠ enΣ oµ thσ inpu⌠ string¼ name.è Noticσ thσ lis⌠ oµ title≤ anΣ honorific≤ tha⌠ caε easil∙ bσ extendeΣ t∩ ì
takσ accoun⌠ oµ militar∙ rank≤ o≥ whatever╗ Listinτ ▓ i≤ jus⌠ aε example.
Incorporatinτ thi≤ kinΣ oµ codσ int∩ ß V2.│ stylσ appenΣ o≥ edi⌠ i≤ ver∙ ì
simple« Thσ pseud∩ codσ remain≤ identical¼ bu⌠ ß D╧ SURNAM┼ commanΣ (o≥ ì
whateve≥ processinτ yo⌡ require⌐ i≤ inserteΣ in-linσ jus⌠ beforσ thσ memor∙ ì
variable≤ arσ replaceΣ int∩ thσ database.
Fo≥ example¼ takσ ß looδ a⌠ Listinτ 3¼ ß simplσ screeε inpu⌠ screeε whicΦ ì
input≤ employeσ timesheet≤ fo≥ ß professiona∞ timσ accountinτ system« Thσ onl∙ ì
bit≤ oµ processinτ are¼ first¼ ß datσ conversioε (%makedate)¼ anΣ theε tw∩ ì
line≤ oµ timσ conversion:
STOR┼ VAL($(trif:time,1,2))+VAL($(trif:time,4,2))/6░ T╧ triform
STOR┼ VAL($(tito:time,1,2))+VAL($(tito:time,4,2))/6░ T╧ tito
It'≤ worthwhilσ takinτ somσ timσ t∩ understanΣ these¼ a≤ the∙ illustratσ ì
ho≈ yo⌡ caε makσ ß characte≥ strinτ oµ thσ forφ 'hh.mmº anΣ conver⌠ i⌠ int∩ ß ì
numeriπ figurσ fo≥ hour≤ anΣ ß decima∞ fractioε oµ aε hour«
VALI─ REASONS
Tw∩ othe≥ technique≤ arσ importan⌠ here« First¼ thσ prograφ illustrate≤ ì
validatioε agains⌠ anothe≥ database« It'≤ important¼ iε an∙ billinτ system¼ ì
tha⌠ worδ i≤ onl∙ donσ fo≥ valiΣ joΓ number≤ anΣ clien⌠ number≤ - otherwisσ i⌠ ì
can'⌠ bσ billed« Thi≤ kinΣ oµ contro∞ i≤ vita∞ t∩ thσ profitablσ operatioε oµ ì
an∙ business¼ a≤ i⌠ eliminate≤ unprofitablσ work« Iε thσ secondar∙ databasσ ì
area¼ wσ havσ openeΣ thσ job≤ database¼ whicΦ i≤ indexeΣ oε thσ concatenatioε ì
oµ clien⌠ numbe≥ anΣ joΓ number« Oncσ thσ forφ ha≤ beeε filleΣ in¼ wσ se⌠ u≡ ß ì
ke∙ valuσ froφ thosσ tw∩ fields¼ selec⌠ secondar∙ anΣ tr∙ t∩ FIN─ thσ ì
appropriatσ record« Iµ wσ can'⌠ finΣ it¼ dBasσ wil∞ returε ß recorΣ numbe≥ oµ ì
0¼ anΣ s∩ wσ wil∞ kee≡ returninτ t∩ edi⌠ thosσ field≤ unti∞ ß valiΣ ì
combinatioε oµ joΓ anΣ clien⌠ numbe≥ ha≤ beeε keyeΣ in.
Thσ seconΣ importan⌠ techniquσ i≤ t∩ usσ thσ prefi° (ti-« meaninτ Timσ ì
Input⌐ beforσ al∞ memor∙ variablσ name≤ t∩ indicatσ tha⌠ the∙ belonτ t∩ thi≤ ì
module« A⌠ thσ end¼ thσ RELEAS┼ AL╠ LIK┼ ti¬ statemen⌠ release≤ onl∙ thosσ ì
variable≤ knowε iε thi≤ mode∞ oµ code╗ an∙ other≤ arσ lef⌠ alone« Oµ course¼ ì
somσ carσ mus⌠ bσ takeε witΦ name≤ wheε usinτ thi≤ technique« Fo≥ example¼ iµ ì
iε ß modulσ calleΣ Maiε AdΣ wσ decidσ t∩ prefi° variablσ name≤ witΦ ma-« theε ì
RELEAS┼ AL╠ LIK┼ ma¬ wil∞ als∩ releasσ ou≥ makedatσ macr∩ variable« Perhap≤ ì
thσ bes⌠ solutioε i≤ t∩ prefi° al∞ globa∞ variable≤ likσ tha⌠ onσ witΦ ß g.
Betweeε them¼ thesσ technique≤ illustratσ ho≈ strinτ handlinτ technique≤ ì
caε bσ useΣ t∩ alte≥ thσ interna∞ storagσ oµ dates¼ time≤ anΣ names« Othe≥ ì
type≤ oµ characte≥ variable≤ caε als∩ bσ handleΣ thi≤ way╗ it'≤ u≡ t∩ yo⌡ t∩ ì
makσ usσ oµ it.
Nex⌠ lessoε wσ looδ a⌠ programminτ stylσ generally¼ witΦ thσ emphasi≤ oε ì
structureΣ programminτ techniques.
FIGURE╙ 1¼ ▓ AN─ │ AR┼ O╬ TH┼ FOLLOWIN╟ PAGES.
è
-----------------------------------------------------------------------------
LISTIN╟ 1« Samplσ routinσ t∩ givσ thσ use≥ freedoφ t∩ typσ thσ datσ iε
an∙ desireΣ format.
-----------------------------------------------------------------------------
¬ DATE.CM─ datσ strippe≥ 4/8┤ b∙ Le≤ Bell.
¬ Inpu⌠ variablσ mdatσ (C⌐ containinτ dd/mm/y∙ o≥ d/m/y∙ o≥ whatever
¬ Outpu⌠ variablσ year¼ month¼ da∙ (N)
storσ @('/',mdate⌐ t∩ slash1
storσ @('/',$(mdate,slash1+1)⌐ t∩ slash▓
iµ slash▓ ╜ 0
storσ val($(mdate,slash1+1)⌐ t∩ year
storσ val($(mdate,1,slash1-1)⌐ t∩ month
storσ ░ t∩ day
else
storσ slash▓ ½ slash▒ t∩ slash2
storσ val($(mdate,slash2+1))⌐ t∩ year
storσ val($(mdate,1,slash1+1,slash2-slash1-1)⌐ t∩ month
storσ val($(mdate,1,slash1-1)⌐ t∩ day
endif
releasσ slash1,slash2
¬ EN─ O╞ LISTIN╟ 1.
-----------------------------------------------------------------------------
LISTIN╟ ▓ O╬ NEX╘ PAGE
èLISTIN╟ 2« Namσ handlinτ routine.
-----------------------------------------------------------------------------
¬ SURNAME.CM─ V3.░ b∙ Le≤ Bel∞ 5/13/84
¬ Pull≤ apar⌠ namσ iε thσ forφ 'Mr« Johε Q.A« Publicº int∩ separatσ fields
¬ Inpu⌠ memor∙ variable║ namσ
¬ Outpu⌠ fields║ title¼ first¼ midinit¼ surname
¬ Workinτ variables║ snd≡ ╜ do⌠ position¼ sns≡ ╜ spacσ position
¬ EstablisΦ iµ therσ i≤ ß titlσ anΣ takσ carσ oµ it.
STOR┼ @(º ',mname⌐ T╧ snsp
STOR┼ @('.',mnane⌐ T╧ sndp
I╞ (snd≡ ╝ sns≡ .AND« snd≡ ú 0)
STOR┼ snd≡ ½ ▒ T╧ snsp
ENDIF
STORE$(mname,1,snsp-1⌐ T╧ snti
I╞ @(!(snti),'MRMRSMISSMSPROFREVDRMR.MRS.MISS.MS.PROF.REV.DR.'⌐ ╛ 0
¬ I≤ i⌠ ß title
REPLAC┼ titlσ WIT╚ sntΘ NOUPDATE
¬ Removσ titlσ froφ name
STOR┼ $(mname,snsp⌐ T╧ mname
ENDI╞
¬ Removσ leadinτ spaces
D╧ WHIL┼ $(mname,1,1⌐ ╜ º '
STOR┼ $(mname,2⌐ T╧ mname
ENDDO
STOR┼ TRIM(mname⌐ T╧ mname
I╞ @(º ',$(mname,1)⌐ ╛ 0
¬ Therσ arσ tw∩ words
¬ Checδ fo≥ firs⌠ name
STOR┼ @(º ',mname⌐ T╧ snsp
STOR┼ @('.',mname⌐ T╧ snd≡
¬ I≤ firs⌠ namσ aε initial
I╞ (snd≡ ╝ sns≡ .AND« snd≡ ú 0)
¬ I⌠ is
REPLAC┼ firs⌠ WIT╚ $(mname,1,sndp⌐ NOUPDATE
STOR┼ $(mname,sndp+1⌐ T╧ mname
ELSE
¬ Firs⌠ worΣ i≤ firs⌠ name
REPLAC┼ firs⌠ WIT╚ $(mname,1,snsp-1⌐ NOUPDATE
STOR┼ $(mname,snsp+1⌐ T╧ mname
ENDIF
¬ Removσ leadinτ spaces
D╧ WHIL┼ $(mname,1,1⌐ ╜ º '
STOR┼ $(MNAME,2⌐ T╧ mname
ENDDO
¬ Checδ fo≥ midinits
REPLAC┼ midini⌠ WIT╚ º º NOUPDATE
STOR┼ @('.',mname⌐ T╧ sndp
D╧ WHIL┼ snd≡ ╛ 0
REPLAC┼ midini⌠ WIT╚ TRIM(midinit⌐ - $(mname,1,sndp⌐ NOUPDATE
STOR┼ $(mname,sndp+1⌐ T╧ mname
D╧ WHIL┼ $(mname,1,1⌐ ╜ º '
STOR┼ $(mname,2⌐ T╧ mname
ENDDO
STOR┼ @('.',mname⌐ T╧ sndp
ENDD╧ cont...è ENDI╞
¬ What'≤ lef⌠ mus⌠ bσ thσ surname
REPLAC┼ surnamσ WIT╚ mname
RELEAS┼ snsp,sndp,snti
¬ EN─ O╞ LISTIN╟ 2.
-----------------------------------------------------------------------------
LISTIN╟ │ START╙ O╬ NEX╘ PAGE.
èLISTIN╟ 3« Screeε inpu⌠ routinσ fo≥ employeσ timesheets.
-----------------------------------------------------------------------------
¬ TIME.CM─
¬ ente≥ time≤ froφ timesheets
US┼ time≤ INDE╪ timid
¬ se⌠ u≡ validatioε fo≥ joΓ numbe≥ anΣ clien⌠ number
SELEC╘ SECONDARY
US┼ job≤ INDE╪ jobid
SELEC╘ PRIMARY
STOR┼ º º T╧ tistaffno
STOR┼ ⌠ T╧ timore
D╧ WHIL┼ timore
STOR┼ º º T╧ disdate
STOR┼ º º T╧ tifr:time
STOR┼ º º T╧ tito:time
STOR┼ º º T╧ ticlientno
STOR┼ º º T╧ tijobno
STOR┼ 000.0░ T╧ tirate
ERASE
└ 4,╕ SA┘ 'Stafµ ID'
└ 4,1╢ GE╘ tistaffn∩ PICTUR┼ '!!!'
└ 4,4░ SA┘ 'Date'
└ 4,4┤ GE╘ disdatσ PICTUR┼ '99/99/99'
└ 5,┤ SA┘ 'Star⌠ Time'
└ 5,1╢ GE╘ tifr:timσ PICTUR┼ '99.99'
└ 5,2╡ SA┘ 'FinisΦ Time'
└ 5,3╢ GE╘ tito:timσ PICTUR┼ '99.99'
└ 7,┤ SA┘ 'Clien⌠ No.'
└ 7,1╢ GE╘ ticlientn∩ PIC╘ '999'
└ 7,2╡ SA┘ 'JoΓ Number'
└ 7,3╢ GE╘ tijobn∩ PICTUR┼ '999999'
└ 9,┤ SA┘ 'Rate'
└ 9,1╢ GE╘ tirate
READ
I╞ tifr:timσ ╜ º '
STOR┼ µ T╧ timore
ELSE
¬ Validatσ clientn∩ anΣ jobno
STOR┼ ticlientno+tijobn∩ T╧ tival
SEL┼ SECO
¬ job≤ databasσ i≤ indexeΣ oε clientno+jobno
FIN─ &tival
D╧ WHIL┼ ú ╜ 0
└ 22,▓ SAY'InvaliΣ joΓ numbe≥ o≥ clien⌠ number« Pleasσ rσ enter'+CHR(7)
└ 7,1╖ GE╘ ticlientn∩ PICTUR┼ '999'
└ 7,3╢ GE╘ tijobn∩ PICTUR┼ '999999'
READ
STOR┼ ticlientno+tijobn∩ T╧ tival
FIN─ &tival
ENDDO
SEL┼ PRIMARY
APPEN─ BLANK
&makedate
STOR┼ VAL($(tifr:time,1,2))+VAL($(tifr:time,4,2))/6░ T╧ tiform
STOR┼ VAL($(tito:time,1,2))+VAL($(tito:time,4,2))/6░ T╧ titoè REPLAC┼ staffn∩ WIT╚ tistaffno¼ datσ WIT╚ mdate
REPLAC┼ from:timσ WIT╚ tiform¼ to:timσ WIT╚ tito
REPLAC┼ clientn∩ WIT╚ ticlientno¼ jobn∩ WIT╚ tijobno¼ ratσ WIT╚ tirate
ENDIF
ENDDO
RELEAS┼ AL╠ LIK┼ ti*
¬ EN─ O╞ LISTIN╟ 3.
EN─ O╞ PAR╘ 10.