CmdrRyan
CmdrRyan

Reputation: 5

calling a label wtih an output of a varriable

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

Answers (2)

Aacini
Aacini

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

RGuggisberg
RGuggisberg

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

Related Questions