Article View: comp.lang.pascal.borland
Article #157Re: Need very good Argument switch program
From: Mr. Veli Suorsa
Date: Thu, 28 Jun 2001 18:41
Date: Thu, 28 Jun 2001 18:41
111 lines
4014 bytes
4014 bytes
Thanks for Your reply, Starlet!
The Scarlet Manuka wrote:
> Program Argun;
> var
> x: integer;
>
> begin
> if ParamCount = 0 then
> doSyntax;
>
> for x := 1 to ParamCount do
> begin
> if ParamStr(x) = '-C' then
> doLongDistanceMobileCall;
> if ParamStr(x) = '-N' then
> doNuclearPower;
> if ParamStr(x) = '-O' then
> doOil;
> if ParamStr(x) = '-R' then
> doRenewables;
> if ParamStr(x) = '-S' then
> doSaving;
> if ParamStr(x) = '-V' then
> doVote;
> if ParamStr(x) = '-W' then
> doWindPower;
> {etc}
> end
> end.
>
> Slightly more efficient would be:
> for x := 1 to ParamCount do
> begin
> if ParamStr(x) = '-C' then
> doLongDistanceMobileCall
> else if ParamStr(x) = '-N' then
> doNuclearPower
> else if ParamStr(x) = '-O' then
> doOil {etc}
>
> Note that the semicolons have been removed, since the "else" means we are
> continuing in the same statement, not starting a new statement.
>
> Better would be to have another couple of variables and do something like
> this:
>
> var
> x: integer;
> arg: string;
>
> begin
> ...
> for x := 1 to ParamCount do
> begin
> arg := ParamStr(x);
> if (length(arg) = 2) and (arg[1] = '-') then
> case arg[2] of
> 'C': doLongDistanceMobileCall;
> 'N': doNuclearPower;
> ...
> 'W': doWindPower;
> end
> end
> end.
Can I use in Pascal something like this case- command (Note: many case-
characters)?
...
case arg of
'-N': doNuclearPower;
...
And of cource all other arguments same way.
> You can avoid case sensitivity by using UpCase(arg[2]) instead of arg[2]
> above.
>
> > void doLongDistanceMobileCall()
> > {
> > printf("Run doLongDistanceMobileCall() !\n");
> > printf("Please, call your partner to buy to you 3G mobile phone!\n");
> >
> > // etc
> > }
>
> function doLongDistanceMobileCall;
> begin
> writeln("Run doLongDistanceMobileCall !");
> writeln("Please, call your partner to buy to you 3G mobile phone!");
> end;
>
> Other functions similarly. Note that your main program needs to come
> *after* all your function definitions.
I will write whole program again, with yours very good advices, thanks. You
must be a teacher or a professional.
With Best Regards
Veli Suorsa
---
"People must believe to the future to be able to live!"
---------------------------------- J.V.Snellman, 1890.
Oulu, FINLAND
Mailto:VJSuorsa@Surfeu.Fi
http://members.surfeu.fi/veli.suorsa/
Technical Details
Message-ID:
<3B3B7A4E.471A1A3F@surfeu.fi>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!195.54.122.107!newsfeed1.bredband.com!bredband!newsfeed1.telenordia.se!algonet!newsfeed1.funet.fi!newsfeeds.funet.fi!193.167.100.82.MISMATCH!news.oamk.fi !not-for-mailReferences:
<3B3A3561.13B23C0F@surfeu.fi> <9hccch$npp$1@fang.dsto.defence.gov.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,325c6695c14dd242 X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,325c6695c14dd242 X-Google-Attributes: gid108ebd,public X-Google-ArrivalTime: 2001-06-28 01:49:17 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!195.54.122.107!newsfeed1.bredband.com!bredband!newsfeed1.telenordia.se!algonet!newsfeed1.funet.fi!newsfeeds.funet.fi!193.167.100.82.MISMATCH!news.oamk.fi !not-for-mail From: "Mr. Veli Suorsa" <veli.suorsa@surfeu.fi> Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal Subject: Re: Need very good Argument switch program Date: Thu, 28 Jun 2001 11:41:25 -0700 Organization: Oulu Lines: 113 Message-ID: <3B3B7A4E.471A1A3F@surfeu.fi> References: <3B3A3561.13B23C0F@surfeu.fi> <9hccch$npp$1@fang.dsto.defence.gov.au> Reply-To: veli.suorsa@surfeu.fi NNTP-Posting-Host: otogate.otol.fi Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: pan.oamk.fi 993717757 7030 193.167.100.74 (28 Jun 2001 08:42:37 GMT) X-Complaints-To: usenet@pan.oamk.fi NNTP-Posting-Date: Thu, 28 Jun 2001 08:42:37 +0000 (UTC) To: The Scarlet Manuka <sacha@maths.uwa.edu.au> X-Mailer: Mozilla 4.08 [en] (Win16; I)