🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #158

Re: Need very good Argument switch program

#158
From: The Scarlet Manuka
Date: Thu, 28 Jun 2001 09:32
39 lines
2618 bytes
"Mr. Veli Suorsa" <veli.suorsa@surfeu.fi> wrote in message
news:3B3B7A4E.471A1A3F@surfeu.fi...
> The Scarlet Manuka wrote:
> >
> >       arg := ParamStr(x);
> >       if (length(arg) = 2) and (arg[1] = '-') then
> >         case arg[2] of
> >           'C': doLongDistanceMobileCall;
> >           'N': doNuclearPower;
> >           ...
> >           'W': doWindPower;
> >         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.

No (I would have suggested it if so; it's much easier). You can't use a
string variable as a case selector, it needs to be an ordinal expression.
Single characters are OK (the char type is an ordinal type), but strings
are not - the best you can do is "if... else if... else if... " chains
for those.

In this case you are only interested in one character, so I suggested the
case construction I gave previously. I think it's probably the nicest way
in this sort of situation; but "if... else if..." is reasonable too.

> I will write whole program again, with yours very good advices, thanks.
You
> must be a teacher or a professional.

Not really, I just have a bit of experience.

--
The Scarlet Manuka
Technical Details
Message-ID: <9hetbt$ch0$1@fang.dsto.defence.gov.au>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news1.optus.net.au!optus!yorrell.saard.net!fang.dsto.defence.gov.au!not-for-mail
References: <3B3A3561.13B23C0F@surfeu.fi> <9hccch$npp$1@fang.dsto.defence.gov.au> <3B3B7A4E.471A1A3F@surfeu.fi>

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 02:30:13 PST
From: "The Scarlet Manuka" <sacha@maths.uwa.edu.au>
Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal
Subject: Re: Need very good Argument switch program
Date: Thu, 28 Jun 2001 17:32:19 +0800
Organization: Defence Science and Technology Organisation
Lines: 41
Message-ID: <9hetbt$ch0$1@fang.dsto.defence.gov.au>
References: <3B3A3561.13B23C0F@surfeu.fi> <9hccch$npp$1@fang.dsto.defence.gov.au> <3B3B7A4E.471A1A3F@surfeu.fi>
NNTP-Posting-Host: un-oranged.dsto.defence.gov.au
X-Trace: fang.dsto.defence.gov.au 993720509 12832 203.6.60.95 (28 Jun 2001 09:28:29 GMT)
X-Complaints-To: postmaster@dsto.defence.gov.au
NNTP-Posting-Date: 28 Jun 2001 09:28:29 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news1.optus.net.au!optus!yorrell.saard.net!fang.dsto.defence.gov.au!not-for-mail