Today we are going to learn "choice" command!
It is really useful in communicating with the client.
It gives a choice of however many you want, determined by the keys you want them to press.
Default keys are Y and N.
choice /n
"/n" hides the choices that you have given, you use this if the choices are already listed.
choice /m
"/m" sends everything behind it as a message, most of the time it is placed last
choice /c
"/c" is the one that allows you to set the choices, let's say if you have "choice /n /c xyz" then there are three choices : x, y and z.
choice /t
"/t" sets the time that the client needs to chose in.
choice /d
"/d" choses the choice after it if time set in "/t" has ran out.
Errorlevel
Errorlevels are important, let's use the last example.
In x, y and z, the first choice is errorlevel 1, followed by 2 and 3.
x is errorlevel 1
y is errorlevel 2
z is errorlevel 3
Here is an example :
@echo off
choice /n /c xyz
if errorlevel 3 goto c
if errorlevel 2 goto b
if errorlevel 1 goto a
:a
ehco You took x
pause => nul
exit
:b
echo You took y
pause => nul
exit
:c
echo You took z
pause => nul
exit
The errorlevels must start from the biggest number and end with the smallest or else it will not work (I don't know the reason as well)
We will be using this command in our next tutorial, and I hope you understood!
沒有留言:
張貼留言