More batch programming...
Now we're ready to
get the maximum power from the choice command. We saw before
that errorlevels are some kind'a number that programs returned
and so on. That was not very useful, I know, but for the choice
The choice program
takes a letter from the keyboard and returns an errorlevel in
consecuence of the key pressed. The sintax is:
CHOICE [text] [/C[:]keys] [/S] [/N] [/T[:]key,secs]
Text is no more
than the text to show when choice is runned.
/C:keys Defines the
possibles keys to be pressed. If no option is present, Y/N are
the keys. For example:
A,B,C,D as possible keys.
you press a not defined key, you'll hear a beep and will continue
as if nothing was pressed.
/S Makes CHOICE
case sensitive. By default, Z is equal to z for choice. With
/S flag present, Z and z are different.
/N Choice shows
the possible keys into brackets when is called. With the /N flag
present, it does not, so that only the text you typed (if so)
defines a key that is taken as default when secs seconds are
passed. For example:
CHOICE Chose drive /C:AC /T:C,5
Shows the message "Chose drive [A,C]" (without quotes)
and, if no key pressed, passed 5 seconds, choses C.
**Way it works
Now we know how to
make the CHOICE sentence. Lets see what happens when CHOICE runs.
It returns an errorlevel number corresponding to the key position
in the /C flag. What???. Well, lets se an example:
|||L____> D gives errorlevel 5
||L_____> C gives errorlevel 4
|L______> B gives errorlevel 3
L_______> A gives errorlevel 1
Now you see that
the errorlevel number depends on nothing but the position of
the key that you gave to CHOICE. That is, when you type
Pressing 2, CHOICE
will give us errorlevel 1, 5 will give
errorlevel 2, 6 errorlevel 3 and 7 errorlevel 4.
Lets see now what
to do with errorlevel. If you remember the IF section, there
IF [NOT] ERRORLEVEL number command
This evaluates the
current errorlevel number. If condition is true the command is
More batch programming--->>