CHOICE


Type: External (6.0 and later)

Syntax:

CHOICE [/C[:]keys] [/N][/S][/T[:]c,nn] [text]

Purpose: Used to provide a prompt so that a user can make a choice while a batch program is running (new with DOS Version 6).

Discussion

This command is used only in batch programs. It is used to display a prompt to the user. The specified prompt is displayed and the program pauses while the user makes a choice from a specified set of keys.

For more information on CHOICE and other batch commands, see Chapter 5, Using Batch Files.

Options

text - Used to specify text to be displayed before the prompt. When text has not been specified, CHOICE will display only the prompt. You must use quote marks around the text if you include a switch character (/) as part of the text.

/C[:]keys - Used to specify the keys that the user can select from when the prompt is displayed. When displayed, the list of key choices will be separated by commas and enclosed in brackets with a question mark at the end. If the /C option is not used, the CHOICE command displays the default key choices of Y and N. The colon [:] is optional.

/N - When the /N option is used the prompt will not be displayed, however the text before the prompt will be displayed and the specified keys will still be valid.

/S - Using the /S option causes CHOICE to be case sensitive to the keys entered by the user at the prompt.

/T[:]c,nn - The /T option can be used to limit the number of seconds the batch program will pause before it defaults to a specified key. The values for the /T switch are:

c - Specifies the default key (character). The key must be one of those specified in the /C switch.

nn - Specifies the length of the pause in seconds (0 to 99).

Example

If you were writing a batch program and wanted to use the CHOICE command to prompt the user to select from the keys Y, N, and C, you would enter the following:

choice /c:ync

The user would see the following prompt:

[Y,N,C]?

To make it more obvious to the user exactly what they are selecting, you could add some explanatory text to the prompt by entering,

choice /c:ync Yes, No, or Continue

The user would then see,

Yes, No, or Continue [Y,N,C]?

If you wanted to use the /T option to limit the amount of time a user has to make a choice at the prompt you might enter,

choice /c:ync /t:c,10

The user would still see the prompt [Y,N,C]? from which they could make their choice. If a selection was not made within 10 seconds the C option would be assumed and the batch program would continue.


Back to the Easy DOS Command Index