I suppose you could do:
@echo off
echo 1 - Start
echo 2 - Stop
choice /c 12 /n
if %errorlevel% == 1 (set /a newvariable=1)
if %errorlevel% == 2 (set /a newvariable=2)
if %newvariable% == 1 (
::execute code
)
if %newvariable% == 2 (
::execute code
)
But is there an simpler, more compact way of doing this?
Also incase you're wonering why I want to do this is because I have the code resembling this:
:function1
if %errorlevel% == 1 (
if %variable1% GEQ 1 (
cls
echo Are you sure?
echo.
echo [1] Yes
echo [2] No
echo.
choice /c 12 /n /m "--"
)
)
if %errorlevel% == 1 (
if %variable1% GEQ 1 (
if %errorlevel% == 1 goto function2
if %errorlevel% == 2 goto function1
)
goto function2
)
if %errorlevel% == 2 (
if %variable1% GEQ 1 (
cls
echo Are you sure?
echo.
echo [1] Yes
echo [2] No
echo.
choice /c 12 /n /m "--"
)
)
if %errorlevel% == 2 (
if %variable1% GEQ 1 (
if %errorlevel% == 1 goto function3
if %errorlevel% == 2 goto function1
)
goto function3
)
The second time you do choice, it sets the errorlevel to something else, and it won't read the second set of code. So a solution I had was to make it different variables.