Batch Variable in Variable name...

July 30, 2010 at 02:42:00
Specs: Windows 7
I have a batch file in which I need to use a variable inside a variable's name. In case that doesn't make sense, here's an example:

@echo off
set FirstVariable=1
set SecondVariable=2
set ThirdVariable=3
set /p choose=Which variable: 
rem On previous line, user would input First, Second, or Third.
rem The next line is where I am having difficulty.
set /a final=34 + %%choose%Variable%
echo final
pause>nul
exit

I need a sum of an integer and that.... thing.
Any advice?


See More: Batch Variable in Variable name...

Report •


#1
July 30, 2010 at 04:04:02
@echo off & setlocal EnableDelayedExpansion
set FirstVariable=1
set SecondVariable=2
set ThirdVariable=3
set /p choose=Which variable:
rem On previous line, user would input First, Second, or Third.
rem The next line is where I am having difficulty.
set /a final=34 + !%choose%Variable!
echo %final%
pause>nul
exit

Report •
Related Solutions


Ask Question