|
CHOICE prompts the user to select one of a specified set of keys in a batch program.
Syntax:
CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]
| /C[:]choices | The prompt - comprising a series of single alphanumeric characters corresponding to valid choices. The prompt is displayed as the characters, separated by commas, enclosed in brackets, and followed by a question mark. Default is YN |
| /N | Stops the prompt from being displayed, although text is still shown and the choices keys are still valid. |
| /S | Forces the choice keys to be case sensitive. By default they are not. |
| /T[:]c,nn | Defaults choice to c after nn seconds. c must exist; nn must be in the range 0 to 99. |
| text | Text displayed before the prompt. Typically, text is used to expand on the subsequent prompt. |
Notes:
The CHOICE command works by assigning an errorlevel value to each entry under choices (see below).
Exit Codes:
| 0 | CHOICE was terminated by Ctrl-C before a choice was entered. |
| 1 | The key corresponding to the first choice was pressed. |
| n | The key corresponding to the nth choice was pressed. |
| 255 | An error occurred. |
Examples:
- Some examples of CHOICE command formats and the corresponding display:
CHOICE
CHOICE /C:ync
CHOICE /C:ync Yes, No, Continue
| Yes, No, Continue [Y,N,C]? |
CHOICE /n Yes, No, or Continue?
CHOICE /C:ync /T:N,5
for 5 seconds; if no key has been pressed by then, N is chosen returning an ErrorLevel value of 2.
- To have the option of running SCANDISK on drive C when the computer is turned on, the following lines could be added to "autoexec.bat":
CHOICE Run Scandisk /ty,5
IF errorlevel 2 GOTO SkipScan
Scandisk c:
:SkipScan
If you press N within 5 seconds, SCANDISK will not run and CHOICE returns an ERRORLEVEL value of 2. If you do not press N within 5 seconds, or if you choose Y, SCANDISK runs on drive C.
- The following batch program uses the CHOICE option to select one of three Dos utilities: Scandisk, Microsoft Backup, or Debug. Notice that the IF ERRORLEVEL statements are listed in decreasing order. MS-Dos will consider the IF statement true if the ERRORLEVEL parameter returned by CHOICE is greater than or equal to the parameter specified in the IF command.
@ECHO off
ECHO A Scandisk
ECHO B Microsoft Backup
ECHO C Debug
CHOICE /C:abc Choose an option
IF errorlevel 3 GOTO Dbug
IF errorlevel 2 GOTO MsBack
IF errorlevel 1 GOTO Scan
:Dbug
Debug
GOTO End
:Scan
Scandisk
GOTO End
:Msbackup
msbackup
GOTO End
:End
File Details
| File Name | Version | Size | Date | Default Location |
| Choice.com |
Win95: Upgrade | 5 175 | 11/07/95 | c:\windows\command |
| Win95: OSR2.5 | 5 175 | 24/08/96 | c:\windows\command |
|