home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug001.arc
/
PART7.IQS
/
PART7.INS
Wrap
Text File
|
1979-12-31
|
11KB
|
218 lines
.po0
dBasσ I╔ PAR╘ 7
Thσ firs⌠ prograφ everybod∙ write≤ i≤ thσ "Hell∩ Worldó program« Iµ ì
you'vσ neve≥ writteε thi≤ onσ before¼ it'≤ ß simplσ prograφ t∩ writσ "hell∩ ì
Worldó oε thσ screen« S∩ iε dBase:
ERASE
┐ 'Hell∩ World'
Thσ ERAS┼ commanΣ clear≤ thσ screen¼ whilσ thσ ┐ symbo∞ print≤ thσ strinτ ì
oε thσ screen« Whilσ thi≤ demonstrate≤ nonσ oµ thσ intricacie≤ oµ thσ dBasσ ì
language¼ a⌠ leas⌠ i⌠ show≤ tha⌠ dBasσ ha≤ nonσ oµ thσ intricacie≤ requireΣ b∙ ì
othe≥ languages« Iε PL/╔ fo≥ example¼ thσ abovσ prograφ is:
world:
proπ options(main):
pu⌠ ski≡ lis⌠ (ascii(26),'Hell∩ World');
enΣ world;
That'≤ onσ oµ thσ thing≤ dBasσ ha≤ goinτ fo≥ it╗ it'≤ relativel∙ eas∙ t∩ ì
writσ shor⌠ program≤ iε it« Yo⌡ don'⌠ eveε havσ t∩ worr∙ abou⌠ linσ numbers!
However¼ program≤ arσ morσ usefu∞ iµ the∙ arσ ablσ t∩ perforφ repetitivσ task≤ ì
o≥ t∩ makσ decision≤ baseΣ upoε thσ value≤ oµ variables« dBasσ provide≤ ß ì
numbe≥ oµ way≤ oµ doinτ this.
Thσ D╧ WHIL┼ statement¼ coupleΣ witΦ ß matchinτ ENDDO¼ i≤ thσ maiε wa∙ oµ ì
controllinτ ß loop« Fo≥ example¼ herσ i≤ thσ wa∙ t∩ writσ ß FOR..NEX╘ loop:
STOR┼ ▒ T╧ control
D╧ WHIL┼ contro∞ ╝ 11
¬ maiε bod∙ oµ loop
┐ control
STOR┼ contro∞ ½ ▒ t∩ control
ENDDO
Thi≤ wil∞ prin⌠ thσ number≤ froφ ▒ t∩ 1░ oε thσ screen« Sincσ dBasσ i≤ ß ì
databasσ manipulatioε language¼ ß morσ commoε usσ oµ thσ D╧ WHIL┼ statemen⌠ i≤ ì
t∩ proces≤ ß databasσ filσ froφ beginninτ t∩ end« Likσ mos⌠ languages¼ dBasσ ì
ha≤ ß functioε calleΣ EOF¼ whicΦ return≤ truσ wheε thσ systeφ read≤ thσ endif-ì
filσ marker« S∩ t∩ proces≤ ß databasσ file¼ thσ followinτ dBasσ fragmen⌠ wil∞ ì
d∩ thσ job:
G╧ TOP
D╧ WHIL┼ .NOT« EOF
¬ maiε bod∙ oµ loop
SKIP
ENDDO
Here¼ thσ SKI╨ instructioε move≥ thσ filσ pointe≥ oε t∩ thσ nex⌠ record« ì
Oncσ thσ fina∞ recorΣ ha≤ beeε processed¼ thσ SKI╨ instructioε wil∞ attemp⌠ t∩ ì
movσ thσ filσ pointe≥ on¼ bu⌠ insteaΣ i⌠ wil∞ bum≡ int∩ thσ end-of-filσ ì
marker« A⌠ thσ to≡ oµ thσ loop¼ thσ WHIL┼ conditioε wil∞ no≈ evaluatσ t∩ ì
false¼ anΣ s∩ thσ bod∙ oµ thσ loo≡ wil∞ no⌠ bσ executed.
è A≤ mentioneΣ above¼ i⌠ i≤ als∩ usefu∞ t∩ bσ ablσ t∩ ac⌠ iε differen⌠ way≤ ì
unde≥ differen⌠ conditions« Iε dBase¼ a≤ iε man∙ othe≥ languages¼ thi≤ i≤ ì
achieveΣ witΦ thσ I╞ ..« ENDI╞ statement« Iε somσ languages¼ thσ operatioε oµ ì
I╞ statement≤ caε seeφ rathe≥ ambiguou≤ thank≤ t∩ thσ lacδ oµ clea≥ indicatioε ì
wherσ thσ scopσ oµ aε I╞ ends¼ bu⌠ iε dBasσ thσ ENDI╞ make≤ i⌠ absolutel∙ ì
clear« S∩ here'≤ aε examplσ oµ thσ I╞ construct:
I╞ zo⌠ ╛ foobar
rangσ ╜ zo⌠ - foobar
ENDIF
Noticσ tha⌠ thσ actioε t∩ bσ performeΣ iµ thσ conditioε i≤ truσ i≤ oε ß ì
separatσ linσ froφ thσ I╞ statemen⌠ itself¼ ß differen⌠ stylσ froφ mos⌠ ì
languages« Notσ tha⌠ yo⌡ arσ no⌠ restricteΣ t∩ jus⌠ onσ statemen⌠ followinτ ì
thσ IF╗ yo⌡ caε havσ a≤ man∙ a≤ requireΣ - jus⌠ finisΦ eacΦ witΦ aε ENDIF.
dBasσ als∩ allow≤ thσ usσ oµ aε ELS┼ clausσ s∩ tha⌠ onσ o≥ othe≥ oµ tw∩ ì
alternative≤ i≤ executed:
I╞ mgros≤ ╝ 0
ta° ╜ 0
ELSE
ta° ╜ mgros≤ ¬ 0.46
ENDIF
Whilσ thσ I╞ ..« ELS┼ ..« ENDI╞ construc⌠ allow≤ thσ selectioε oµ onσ oµ ì
tw∩ course≤ oµ action¼ ß frequen⌠ occurrencσ i≤ thσ requiremen⌠ t∩ selec⌠ onσ ì
oµ man∙ alternatives« Thi≤ i≤ donσ b∙ thσ D╧ CAS┼ statement¼ whicΦ take≤ thσ ì
genera∞ form:
D╧ CASE
CAS┼ statement
statements
CAS┼ expression2
statements
CAS┼ expression3
statements
OTHERWISE
statements
ENDCAS┼
Thi≤ allow≤ thσ programme≥ t∩ handlσ an∙ numbe≥ oµ separatσ cases¼ plu≤ ß ì
fina∞ se⌠ oµ statement≤ t∩ handlσ thσ situatioε wheε nonσ oµ thσ case≤ i≤ ì
true.
Thσ majo≥ usσ oµ thi≤ expressioε i≤ Θ ε menus¼ wherσ thσ use≥ ha≤ t∩ ì
selec⌠ onσ oµ severa∞ alternatives« Here'≤ aε example:
ERASE
D╧ WHIL┼ t
└ 5,1▓ SA┘ 'AdΣ Names'
└ 6,1▓ SA┘ 'Deletσ Names'
└ 7,1▓ SA┘ 'Quit'
└ 21,1▓ SA┘ 'Choice'
SE╘ CONSOL┼ OF╞ cont...è WAI╘ T╧ mchoice
SE╘ CONSOL┼ ON
mchoicσ ╜ !(mchoice)
D╧ CASE
CAS┼ mchoicσ ╜ 'Aº D╧ addnam
CAS┼ mchoicσ ╜ 'Bº D╧ delnam
CAS┼ mchoicσ ╜ 'Qº ERASE
CANCEL
OTHERWISE
┐ CHR(7)
ENDCASE
ENDDO
Thi≤ examplσ show≤ ß fe≈ feature≤ oµ dBase« First¼ wσ havσ no⌠ previousl∙ ì
seeε thσ ERAS┼ command╗ i⌠ simpl∙ clear≤ thσ screeε (thinδ oµ CL╙ iε TRS-8░ o≥ ì
MICROWORL─ BASIC)« Nex⌠ thσ D╧ WHIL┼ t║ iε thi≤ case¼ ⌠ i≤ no⌠ ß variablσ - ì
insteaΣ i⌠ i≤ thσ logica∞ constan⌠ true« Thσ resul⌠ oµ thi≤ i≤ tha⌠ truσ i≤ ì
alway≤ true¼ s∩ thσ loo≡ alway≤ executes« Thσ onl∙ wa∙ ou⌠ i≤ t∩ selec⌠ "Q".
Nex⌠ there'≤ thσ └ commands¼ whicΦ positioε thσ curso≥ oε thσ screeε ì
beforσ output¼ anΣ thσ SA┘ command≤ whicΦ actuall∙ perforφ thσ output« Thσ ì
dBasσ screeε extend≤ froφ 0,░ iε thσ to≡ lef⌠ corne≥ t∩ 23,7╣ iε thσ bottoφ ì
righ⌠ « S∩ thσ firs⌠ threσ └ ..« SAY≤ outpu⌠ thσ men⌡ choice≤ oε threσ ì
successivσ lines¼ 1▓ space≤ froφ thσ lef⌠ hanΣ edgσ oµ thσ screen« We'l∞ seσ ß ì
lo⌠ morσ oµ └ ..« SA┘ later.
WAI╘ FO╥ I╘
Thσ WAI╘ T╧ statemen⌠ get≤ thσ single-characte≥ selectioε froφ thσ ì
user¼ anΣ thσ SE╘ CONSOL┼ command≤ whicΦ bracke⌠ i⌠ simpl∙ suppresse≤ thσ ì
appearencσ oµ thσ WAITIN╟ messagσ tha⌠ woulΣ otherwisσ mes≤ u≡ ou≥ beautifu∞ ì
screen« ┴ curiou≤ fac⌠ abou⌠ user≤ i≤ tha⌠ the∙ thinδ "aó anΣ "Aó arσ thσ samσ ì
lette≥ - whicΦ the∙ obviousl∙ arσ not« T∩ overcomσ this¼ wσ conver⌠ an∙ lower-ì
casσ int∩ upper-case¼ usinτ thσ !(⌐ function.
No≈ come≤ thσ casσ statemen⌠ « Iε thσ firs⌠ tw∩ cases¼ wσ responΣ t∩ thσ ì
user'≤ reques⌠ b∙ runninτ ß commanΣ filσ (ADDNAM.CM─ o≥ DELNAM.CMD)¼ bu⌠ ì
noticσ iµ you≥ tryinτ thi≤ examplσ tha⌠ iµ yo⌡ don'⌠ cratσ thesσ file≤ you'l∞ ì
ge⌠ aε erro≥ message« Eveε empt∙ file≤ wil∞ do¼ thougΦ yo⌡ won'⌠ seσ mucΦ ì
happening.
Fo≥ thσ qui⌠ option¼ wσ clea≥ thσ screeε beforσ CANCELlinτ thσ curren⌠ ì
anΣ highe≥ commanΣ file≤ - iε othe≥ words¼ returninτ t∩ thσ commanΣ level« ì
Finally¼ iµ wσ haven'⌠ recogniseΣ thσ user'≤ inpu⌠ b∙ thi≤ stage¼ wσ prin⌠ ì
ASCI╔ characte≥ numbe≥ 7¼ whicΦ ring≤ thσ bel∞ o≥ beeps¼ anΣ theε redisplay≤ ì
thσ menu.
Ou≥ majo≥ examplσ thi≤ lessoε i≤ ß simplσ repor⌠ oε thσ booksho≡ ì
database« Yo⌡ ma∙ recal∞ tha⌠ thσ BKINV.DB╞ ha≤ to∩ man∙ field≤ t∩ lis⌠ oε aε ì
8░ columε printer╗ iµ you'rσ lucky¼ your'≤ ma∙ wra≡ arounΣ automatically¼ bu⌠ ì
minσ jus⌠ overtype≤ thσ samσ line« Ho≈ theε caε yo⌡ prin⌠ thσ content≤ oµ thσ ì
database┐ Thσ prograφ list≤ thσ content≤ oµ thσ databasσ oε fivσ lines¼ witΦ ì
ß sixtΦ linσ oµ dashe≤ t∩ separatσ eacΦ recorΣ froφ thσ next« I⌠ als∩ ì
automaticall∙ insert≤ pagσ breaks.
è SE╘ TAL╦ OFF
US┼ bkinv
SE╘ FORMA╘ T╧ PRINT
SE╘ MARGI╬ T╧ 0
D╧ WHIL┼ .NOT« EOF
STOR┼ ░ T╧ count
D╧ WHIL┼ coun⌠ ╝ 1░ .AND« .NOT« EOF
STOR┼ coun⌠ ¬ ╢ T╧ pagepos
└ pagepos+0¼ ░ SA┘ 'Stocδ Number:'
└ pagepos+0,1┤ SA┘ stockno
└ pagepos+1¼ ░ SA┘ 'Title:'
└ pagepos+1¼ ╕ SA┘ title
└ pagepos+2¼ ░ SA┘ "Author"
└ pagepos+2¼ ╕ SA┘ author
└ pagepos+3¼ ░ SA┘ "Publisher"
└ pagepos+3,1▒ SA┘ publisher
└ pagepos+3,2╖ SA┘ "Sel∞ Price"
└ pagepos+3,3╣ SA┘ sell:price
└ pagepos+3,5│ SA┘ "Bu∙ Price"
└ pagepos+3,6┤ SA┘ buy:price
└ pagepos+4¼ ░ SA┘ "Stocδ oε Hand"
└ pagepos+4,1╡ SA┘ stock
└ pagepos+4,2╖ SA┘ "Bacδ Ordered"
└ pagepos+4,4▒ SA┘ backorder
└ pagepos+5,5│ SA┘ "Reorde≥ Level"
└ pagepos+4,6╕ SA┘ reorder
└ pagepos+5,3░ SA┘ "------------------------------"
SKIP
STOR┼ COUN╘ +▒ T╧ count
ENDDO
ENDDO
SE╘ FORMA╘ T╧ SCREEN
Thi≤ i≤ ß reasonabl∙ straigh⌠ forwarΣ prograφ - i⌠ look≤ morσ comple° ì
thaε i⌠ reall∙ is« Thσ firs⌠ fe≈ statement≤ opeε thσ databasσ filσ anΣ se⌠ thσ ì
initia∞ conditions« SE╘ FORMA╘ T╧ PRIN╘ mean≤ tha⌠ subsequen⌠ └ ..« SAY'≤ wil∞ ì
bσ sen⌠ t∩ thσ printer« Wσ havσ decideΣ t∩ prin⌠ ß recorΣ ove≥ si° lines¼ ì
whicΦ mean≤ tha⌠ wσ caε fi⌠ teε oε ß page« S∩ wσ firs⌠ oµ al∞ se⌠ u≡ ß maiε ì
loo≡ whicΦ print≤ ß pagσ a⌠ ß timσ - that'≤ thσ D╧ WHIL┼ .NOT« EOF« T∩ prin⌠ ß ì
pagσ wσ simpl∙ coun⌠ teε records« Note¼ however¼ tha⌠ iµ wσ arσ onl∙ fivσ ì
record≤ awa∙ froφ thσ enΣ oµ thσ filσ wheε wσ star⌠ printing¼ wσ can'⌠ prin⌠ ì
teε record≤ (actuall∙ we'l∞ ge⌠ thσ las⌠ recorΣ printeΣ si° times)« S∩ wσ havσ ì
t∩ includσ ß tes⌠ fo≥ end-of-file≤ iε thσ inne≥ loo≡ a≤ well.
Nex⌠ wσ worδ ou⌠ thσ linσ wherσ thi≤ particula≥ recorΣ shoulΣ bσ printeΣ ì
oε thσ pagσ - that'≤ coun⌠ si° times« Theε wσ prin⌠ thσ record¼ startinτ a⌠ ì
tha⌠ line« Wheε aε └ ..« SA┘ i≤ sen⌠ t∩ thσ printer¼ dBasσ examine≤ thσ linσ ì
numbe≥ iε relatioε t∩ it≤ curren⌠ linσ position« Iµ i⌠ i≤ alread∙ pas⌠ tha⌠ ì
position¼ i⌠ wil∞ automaticall∙ inser⌠ ß pagσ ejec⌠ anΣ g∩ t∩ thσ righ⌠ ì
positioε oε thσ nex⌠ pagσ - ß featurσ wσ coun⌠ oε t∩ ge⌠ pagσ eject≤ ever∙ teε ì
records¼ a≤ thσ pagepo≤ goe≤ froφ 5┤ t∩ 0« A⌠ thσ enΣ oµ thσ loo≡ wσ ski≡ ì
forwarΣ iε thσ database¼ incremen⌠ coun⌠ anΣ we'rσ done« Onσ thinτ t∩ watcΦ ì
abou⌠ thi≤ (anΣ other⌐ commanΣ file≤ i≤ tha⌠ i⌠ leave≤ TAL╦ se⌠ OFF¼ s∩ tha⌠ ì
iµ yo⌡ arσ experimentinτ witΦ dBase¼ o≥ makinτ adhoπ enquirie≤ usinτ SU═ o≥ ì
COUNT¼ everythinτ wil∞ g∩ quiet.
END PART 7è