Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
:EndIftikhar Ahmad
Brainbench MVP for Windows 95
www.brainbench.com

![]() |
networking question
|
drag and drop unallowed
|

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