Reputation: 5
I am trying to do something like this:
@echo off
:beginning
choice /c:123
if %errorlevel%== 1 set test= aaa
if %errorlevel%== 2 set test= bbb
if %errorlevel%== 3 set test= ccc
call :%test%one
pause
goto beginning
:aaaone
echo phrase
exit /b
:bbbone
echo phrase
exit /b
:cccone
echo phrase
exit /b
and I'm trying to get the call :%test%one to call the output of whatever the errorlevel is but it won't recognize the output of the variable "test" for %test% and says that it cant find the label. Is there a way to get the user to choose what the program calls instead of just using "goto (label)"? Thank you in advance for any advice you might have.
Upvotes: 0
Views: 49
Reputation: 67326
You may also use a different, simpler form, like this:
@echo off
:beginning
choice /c:123
call :%errorlevel%one
pause
goto beginning
:1one
echo phrase
exit /b
:2one
echo phrase
exit /b
:3one
echo phrase
exit /b
Upvotes: 1
Reputation: 4750
You need to remove the spaces after = in these lines:
if %errorlevel%==1 set test=aaa
if %errorlevel%==2 set test=bbb
if %errorlevel%==3 set test=ccc
Upvotes: 3