1

I was trying to do something like this, becouse I'm writing a program where this thing could be very useful.

echo which integer do you want?
echo 1
echo 2
set 1d=10
set 2d=110
set /p a=
echo %'%a%d'%   //This part sould display eather 10 or 110 based on the value of integer a.

It would be so mutch easier than makeing 1000th of if structures...

Thanks the helps in advice.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • 1
    What you are looking for is called [array](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990). Note that defining variables that start with digit is not a good idea... – Aacini Aug 23 '18 at 09:24
  • Don't use variable names that begin with a numeral, because the `%#` part might be interpreted as an [argument](http://ss64.com/nt/syntax-args.html) of the batch file... – aschipfl Aug 27 '18 at 11:23

1 Answers1

1

SETLOCAL EnableDelayedExpansion is what you are looking for:

@ECHO OFF
SETLOCAL EnableDelayedExpansion
echo which integer do you want?
echo 1
echo 2
set 1d=10
set 2d=110
set /p a=
echo !%a%d!

Check this website for more information.

MichaelS
  • 5,941
  • 6
  • 31
  • 46