Hello,
Is it possible to echo the value of a variable when the name of the variable is itself a variable.
I have (stripping other nonsence)
:loop
set cols=0
set /a c%cols%=%random%
set /a cols=%cols%+1
if cols==10 (goto :wherever) else (goto :loop)
And i want to be able to echo whatever %random% is which will be stored under whatever value is generate by c%cols%
This required (i think) a double expansion of a variable, but i cannot convince dos to do this.
Any ideas?
double expansion of variables
Moderator: DosItHelp
dizze,
Yes you can, in your case use:
Before executing the line the command interpreter will resolve:
%cols% --> value of cols variable
%% ------> %
Assuming the value of the cols variable is 0 and the value of c0 is 12345 this means:
will be resolved to:
Then the command line will be executed starting with call command which again will make the command interpreter resolve all variables first:
Hope this helps
Yes you can, in your case use:
Code: Select all
call echo.%%c%cols%%%
Before executing the line the command interpreter will resolve:
%cols% --> value of cols variable
%% ------> %
Assuming the value of the cols variable is 0 and the value of c0 is 12345 this means:
Code: Select all
call echo.%%c%cols%%%
will be resolved to:
Code: Select all
call echo.%c0%
Then the command line will be executed starting with call command which again will make the command interpreter resolve all variables first:
echo.12345
Hope this helps
Sucess!
Thanks DosItHelp ,
That works perfectly, i can now get rid of my tempory file hack.
Dizz-E
That works perfectly, i can now get rid of my tempory file hack.
Dizz-E