[Date Prev][Date Next][Subject Prev][Subject Next][
Date Index][
Subject Index]
Re: Autoexec.nt commands
- Subject: Re: Autoexec.nt commands
- From: "Robert Holmgren" holmgren@xxxxxxxx
- Date: Thu, 23 Aug 2007 23:19:15 -0400
** Reply to message from Harry Binswanger on
Thu, 23 Aug 2007 16:48:10 -0400
> Re Robert's CHOICE.BAT using SET /P
> It works. I got a strange result when I hit ENTER
> instead of responding with y/N:
> Yes was unexpected at this time.
The ONLY reason you got that is that you did NOT follow my
template and example! So don't misrepresent it as "Robert's
CHOICE.BAT", because your code is NOT my example CHOICE.BAT. I
don't know what your code says, but it isn't the same. It seems
to me that when you're LEARNING, you don't "do it your way" and
omit the things you don't understand, and then ask why the whole
doesn't work. If you'd started with my example, you wouldn't
get that "strange" result.
Specifically, your code omits the critical line:
if %oui%!==! set oui=N
Then you hit Enter without first entering any text (a
contingency that my code handles, and your code does not --
that's how I know you omitted the line). Therefore variable OUI
was empty. Therefore "y is unexpected" because variable OUI
doesn't exist. Something that doesn't exist cannot equal "y"
and may be said to be utterly "unexpected". (How do we wipe out
an environment variable? By entering "SET VARIABLENAME="! And
that's what you did, when you hit Enter without first entering
any text, i.e. value=null.)
You MUST include code to trap an empty/nonexistent VARIABLE if
you intend further evaluation. And that's why the *first* line
after SET /P is:
if %oui%!==! set oui=N
If %oui% doesn't exist, then "!" will equal "!". Put another
way, if "!" equals "!" then %oui% MUST necessarily be null.
It's a simple equation. Not to mention, a basic BATCH concept
dating from primordial times... Because I define the default to
be "N"o -- and I tell you so with the convention "(y/N)" -- I
therefore set OUI=N after an empty response.
>> if %oui%==y set oui=Y
> ... Interestingly, the user-response is not case-sensitive.
> I.e., Y and y produce the same "OK."
Isn't the line you quote self-evident? The line means: "if OUI
= y then OUI = Y". It uppercases user's response, in order that
user's response can be evaluated henceforth solely in UPPERCASE
-- so that the BATchfile ongoing doesn't need to test both lower
and UPPER case. Which ought to be completely obvious from the
next two lines, which do not consider a lowercase response.
This is what I was complaining about a few weeks ago: hitting
the Help button instead of struggling and thinking first, and
thereby shifting the burden -- creating unnecessary burden -- as
well as sowing doubt in the minds of hundreds of subscribers
that a pie-simple & nearly braindead procedure may not be as
easy as it looks. That there may be "unexpected wrinkles"!
Really irritating. Because actually, you just botched it --
willfully!
-----------------------------
Robert Holmgren
holmgren@xxxxxxxx
-----------------------------