Solved 'Choice' not working

September 7, 2011 at 19:24:55
Specs: Windows 7
I'm pretty much a begginer at writing batch files, so I wanted to learn how to use the choice command, and I came up with this basic program,

@echo off
:BEGIN
echo Testing 'Choice'
CHOICE /C:123 /N /M "Press One, Two or Three"
IF ERRORLEVEL ==1 GOTO ONE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==3 GOTO THREE
GOTO END
:THREE
ECHO You Pressed Three
GOTO END
:TWO
ECHO You Pressed Two
GOTO END
:ONE
ECHO You Pressed One
GOTO END
:END
Pause

Whenever you press any number, the program always says you pressed 1. Can anyone tell me what I'm doing wrong here?


See More: Choice not working

Report •

#1
September 8, 2011 at 00:25:21
✔ Best Answer
IF %ERRORLEVEL%==1 GOTO ONE
IF %ERRORLEVEL%==2 GOTO TWO
IF %ERRORLEVEL%==3 GOTO THREE


Report •

#2
September 8, 2011 at 06:40:57
Thanks, the source I was getting this from didn't mention the need for the '%'s.



Report •

#3
September 8, 2011 at 12:37:21
It isn't actually a need, most people find it easier to understand using the variable.

"if errorlevel" evaluates to "greater than or equal to". To use that method the numbers must be checked in descending order(as per the source post).


Report •

Related Solutions

#4
September 8, 2011 at 16:40:41
Wait, I thought MS removed Choice.com from Windows XP and onward.

Mouse could not be found. Click OK to continue.
What to do now?


Report •

#5
September 9, 2011 at 03:07:45
@RMT2

Reintroduced in vista. Though slightly hobbled modified.


Report •

Ask Question