Article View: comp.lang.pascal.borland
Article #159Re: Need very good Argument switch program
From: Frank Peelo
Date: Thu, 28 Jun 2001 09:59
Date: Thu, 28 Jun 2001 09:59
73 lines
3106 bytes
3106 bytes
"The Scarlet Manuka" <sacha@maths.uwa.edu.au> wrote in message
news:9hetbt$ch0$1@fang.dsto.defence.gov.au...
> "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
or case UpCase(arg[2]) if you didn't want to be case-sensitive
...
> > 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.
it is possible to convert the string to an integer by searching in a
larger string, as in the following example which compiles in BP7:
Const
parCall = '-C';
parNuke = '-N';
parWind = '-W';
Params : String =
parCall+#0
+parNuke+#0
+parWind+#0;
posCall=1;
posNuke=posCall+length(parCall)+1;
posWind=posNuke+length(parNuke)+1;
var
i : Integer;
Begin
writeln(ParamCount,' parameters');
For i := 1 to ParamCount do
Begin
write(i,': "',ParamStr(i),'" - ');
case pos(paramStr(i)+#0, Params) of
posCall: Writeln('Call');
posNuke: Writeln('Nuke');
posWind: Writeln('Wind');
else
writeln('Unrecognised');
end;
end;
end.
but it's probably more trouble than it's worth.
FP
Technical Details
Message-ID:
<9heus0$al2$1@kermit.esat.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.esat.net!kermit.esat.net!not-for-mailReferences:
<3B3A3561.13B23C0F@surfeu.fi> <9hccch$npp$1@fang.dsto.defence.gov.au> <3B3B7A4E.471A1A3F@surfeu.fi> <9hetbt$ch0$1@fang.dsto.defence.gov.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 108ebd,325c6695c14dd242 X-Google-Attributes: gid108ebd,public X-Google-Thread: 111659,325c6695c14dd242 X-Google-Attributes: gid111659,public X-Google-ArrivalTime: 2001-06-28 02:54:09 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.esat.net!kermit.esat.net!not-for-mail From: "Frank Peelo" <fpeelo@eircom.net> Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal Subject: Re: Need very good Argument switch program Date: Thu, 28 Jun 2001 10:59:11 +0100 Organization: Esat Net Customer Lines: 75 Message-ID: <9heus0$al2$1@kermit.esat.net> References: <3B3A3561.13B23C0F@surfeu.fi> <9hccch$npp$1@fang.dsto.defence.gov.au> <3B3B7A4E.471A1A3F@surfeu.fi> <9hetbt$ch0$1@fang.dsto.defence.gov.au> NNTP-Posting-Host: 193.120.140.50 Mime-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Trace: kermit.esat.net 993722048 10914 193.120.140.50 (28 Jun 2001 09:54:08 GMT) X-Complaints-To: abuse@esat.net NNTP-Posting-Date: Thu, 28 Jun 2001 09:54:08 +0000 (UTC) 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