Ok. there are several points here; the first one is that the set /A
command may work with just the names of variables, so all your variable expansions are not needed. This should work:
set /a A=A1+A2+A3+A4+A5+A6+A7+A8+A9
set /a B=B1+B2+B3+B4+B5+B6+B7+B8+B9
set /a C=C1+C2+C3+C4+C5+C6+C7+C8+C9
set /a D=D1+D2+D3+D4+D5+D6+D7+D8+D9
set "TestTheAnswer= The following lines are wrong:"
if %A% NEQ 45 set "TestTheAnswer=%TestTheAnswer% A,"
if %B% NEQ 45 set "TestTheAnswer=%TestTheAnswer% B,"
if %C% NEQ 45 set "TestTheAnswer=%TestTheAnswer% C,"
if %D% NEQ 45 set "TestTheAnswer=%TestTheAnswer% D,"
echo %TestTheAnswer:~0,-1%
However, a collection of variables with same name and a changing subscript is called "array", and the advantages of arrays is that you don't need to explicitly write each element of the array, but just write one element and change the subscript via a for
command. Also, you may make good use of the fact that set /A
command allows to perform several operations separating each one with a comma:
setlocal EnableDelayedExpansion
for /L %%i in (1,1,9) do set /A A+=A%%i, B+=B%%i, C+=C%%i, D+=D%%i
set "TestTheAnswer= The following lines are wrong:"
for %%v in (A B C D) do if !%%v! NEQ 45 set "TestTheAnswer=!TestTheAnswer! %%v,"
echo %TestTheAnswer:~0,-1%
For further details on array management in Batch files, see: Arrays, linked lists and other data structures in cmd.exe (batch) script
PS - Your question is about "add several variables to one variable"; a parameter is a different thing. I suggest you to change the topic title.