中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-11-20 04:43
47,820 topics / 349,938 posts / today 0 new / 48,297 members
DOS学习入门 & 精彩文章 (教学室) » About the choice command
Printable Version  4,782 / 17
Floor16 槛之外 Posted 2004-06-25 00:00
初级用户 Posts 6 Credits 138
CHOICE: The CHOICE command. This is a DOS external command, but it is mainly used in batch files.

After the CHOICE command is executed, it will prompt for selectable items, and then select by pressing a key.

Usage: CHOICE key list] selected value, seconds]
Among them, /C means selectable keys, /N means not to display the prompt information, /S means case-sensitive mode, /T means if there is no selection within the specified time, automatically execute a certain selection value defined in /C. The prompt text is the prompt information when the CHOICE command is executed. The selection result will be represented by the ERRORLEVEL value.

IF ERRORLEVEL error return code command
Meaning: If the error return code is greater than or equal to the specified code, a certain command will be executed.
Among them, ERRORLEVEL represents the error return code, which is very useful. For many DOS commands, due to different execution results (such as successful execution, failed execution, or interrupted by the user, etc.), these commands will return different codes to indicate different results. The IF ERRORLEVEL command executes different commands according to the different codes generated by this different result, and is usually used after a certain command. For example, IF ERRORLEVEL 1 ECHO OK! means that if the current error return code is greater than or equal to 1, the words "OK!" will be displayed on the screen
Floor17 tasmzz Posted 2009-04-04 00:41
初级用户 Posts 24 Credits 43
Here's the translation: Give you a piece of code, you try it yourself! choice /c:yn /t:n,5 yes, no,
Floor18 SinLow Posted 2009-09-17 03:31
初级用户 Posts 33 Credits 70
But Windows XP doesn't have this function anymore!

choice is only available in: MS-DOS 6.0+, Windows 95, Windows 98, Windows Vista, Windows 7!!!




Windows XP uses set,
Here's a piece of code for you to try it yourself! !!!!
Just understand it yourself!!!

@ECHO off
cls
:start
ECHO.
ECHO 1. Print Hello
ECHO 2. Print Bye
ECHO 3. Print Test
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto hello
if '%choice%'=='2' goto bye
if '%choice%'=='3' goto test
ECHO "%choice%" is not valid please try again
ECHO.
goto start
:hello
ECHO HELLO
goto end
:bye
ECHO BYE
goto end
:test
ECHO TEST
goto end
:end
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023