Computing.Net > Forums > Windows XP > DOS Choice command replacement

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS Choice command replacement

Reply to Message Icon

Name: wardlawb
Date: February 15, 2003 at 18:44:00 Pacific
OS: XP
CPU/Ram: PIII 933MHz/384MB
Comment:

What DOS Command can be used by Windows XP users to replace the DOS Choice command?



Sponsored Link
Ads by Google

Response Number 1
Name: Iftikhar Ahmad
Date: February 15, 2003 at 22:07:40 Pacific
Reply:

Choice command is not available in Windows 2000 or XP, You can use SET command as an alternate.

The SET command's /P switch lets you prompt for user input. For example, SET /P Choice=Type the letter and press Enter will set the environment variable Choice to whatever the user enters.

The IF command has an /I switch for case-insensitive comparisons. Used together, those features let you create a menu much as you could with CHOICE.

The code below shows a simple example.

@ECHO OFF
CLS
:LOOP
ECHO 1. Option 1
ECHO 2. Option 2
ECHO 3. Option 3
ECHO 4. Quit
SET Choice=
SET /P Choice=Type the digit and press Enter
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='1' GOTO Option1
IF /I '%Choice%'=='2' GOTO Option2
IF /I '%Choice%'=='3' GOTO Option3
IF /I '%Choice%'=='4' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:Option1
ECHO Insert commands for Option 1.
GOTO Again
:Option2
ECHO Insert commands for Option 2.
GOTO Again
:Option3
ECHO Insert commands for Option 3.
GOTO Again
:Again
PAUSE
CLS
GOTO Loop
:End

Iftikhar Ahmad
Brainbench MVP for Windows 95
www.brainbench.com


0
Reply to Message Icon

Related Posts

See More


networking question drag and drop unallowed



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: DOS Choice command replacement

Using choice command in XP www.computing.net/answers/windows-xp/using-choice-command-in-xp/99828.html

DOS: SET /P not waiting for input www.computing.net/answers/windows-xp/dos-set-p-not-waiting-for-input/166469.html

Using the DOS dir command in WINXP www.computing.net/answers/windows-xp/using-the-dos-dir-command-in-winxp/76102.html