I'm having a problem with a choice menu executing the proper errorlevel. My batch file goes to the first item (A), and executes that no matter which choice I select by keyboard in the menu. In the sample below, if I select 'C', then (IF "%ERRORLEVEL%" =="c" GOTO :c495)
should execute. My problem is that (IF "%ERRORLEVEL%" =="a" GOTO :a299)
is executing no matter what key I press. Can someone please tell me what is wrong with my batch file?
@echo off
cls
echo.
echo A $2.99 H $4.99
echo B $3.99 I $9.99
echo C $4.95 J $14.95
echo D $5.99 K $19.95
echo E $6.99 L $29.95
echo F $8.99 M $39.95
echo G $9.95 N $49.95
echo ___________________________________
echo.
echo Press 'Q' to Quit
echo.
CHOICE /N /C:abcdefghijklmnq /M " SELECT A LETTER "%1
IF "%ERRORLEVEL%" =="q" GOTO :xEOF
IF "%ERRORLEVEL%" =="n" GOTO :n4995
IF "%ERRORLEVEL%" =="m" GOTO :m3995
IF "%ERRORLEVEL%" =="l" GOTO :l2995
IF "%ERRORLEVEL%" =="k" GOTO :k1995
IF "%ERRORLEVEL%" =="j" GOTO :j1495
IF "%ERRORLEVEL%" =="i" GOTO :i999
IF "%ERRORLEVEL%" =="h" GOTO :h499
IF "%ERRORLEVEL%" =="g" GOTO :g995
IF "%ERRORLEVEL%" =="f" GOTO :f899
IF "%ERRORLEVEL%" =="e" GOTO :e699
IF "%ERRORLEVEL%" =="d" GOTO :d599
IF "%ERRORLEVEL%" =="c" GOTO :c495
IF "%ERRORLEVEL%" =="b" GOTO :b399
IF "%ERRORLEVEL%" =="a" GOTO :a299
:a299
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 299.png" "blank12.png"
GOTO :Compile
:b399
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 399.png" "blank12.png"
GOTO :Compile
:c495
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 495.png" "blank12.png"
GOTO :Compile
:d599
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 599.png" "blank12.png"
GOTO :Compile
The code goes on from here, but works fine from this point on. Thank you.
This is the way I would do it:
@echo off
cls
echo/
echo A $2.99 H $4.99
echo B $3.99 I $9.99
echo C $4.95 J $14.95
echo D $5.99 K $19.95
echo E $6.99 L $29.95
echo F $8.99 M $39.95
echo G $9.95 N $49.95
echo ___________________________________
echo/
echo Press 'Q' to Quit
echo/
CHOICE /N /C:abcdefghijklmnq /M " SELECT A LETTER "
goto option-%errorlevel%
:option-1 a299
ECHO a299
GOTO :EOF
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 299.png" "blank12.png"
GOTO :Compile
:option-2 b399
ECHO b399
GOTO :EOF
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 399.png" "blank12.png"
GOTO :Compile
:option-3 c495
ECHO c495
GOTO :EOF
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 495.png" "blank12.png"
GOTO :Compile
:option-14 n4995
ECHO n4995
GOTO :EOF
IF NOT EXIST "*Cover (300 DPI).jpg" GOTO :NullFile
IF EXIST "*Cover (300 DPI).jpg" COPY "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - 599.png" "blank12.png"
GOTO :Compile
:option-15 q
ECHO QUIT
PS - I don't understand the comments about a "maximum of 9 options in choice command". Choice allows as possible options all digits and letters (upcase and lowcase may be different) and some special characters, so it may have more than 62 different options...
... and a much simpler method:
@echo off
setlocal
set "list=299,399,495,599,699,899,995,499,999,1495,1995,2995,3995,4995"
cls
echo/
echo A $2.99 H $4.99
echo B $3.99 I $9.99
echo C $4.95 J $14.95
echo D $5.99 K $19.95
echo E $6.99 L $29.95
echo F $8.99 M $39.95
echo G $9.95 N $49.95
echo ___________________________________
echo/
echo Press 'Q' to Quit
echo.
CHOICE /N /C:abcdefghijklmnq /M " SELECT A LETTER "
if %errorlevel% equ 15 goto :EOF
for /F "tokens=%errorlevel% delims=," %%a in ("%list%") do set "file=%%a"
echo File: "c:\Users\admin\Documents\ProgramData\Bin\Prices\3D Cover - %file%.png"