Batch - variable inside variable

April 12, 2009 at 08:00:05
Specs: Windows Vista
@echo off
setlocal enabledelayedexpansion

:::::::::::::::::::::::::::::::::::::::::::::::::
:: This is a section of something I'm doing in batch
::
:: The first part works, but the second part doesn't quite work.
:: It's displaying the variable names, rather than the values.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This first part, I know it works. It sets a buncha variables,
:: from {1,1}, to {9,9}, to be "#".
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

for /L %%y IN (1,1,9) do (
for /L %%x IN (1,1,9) do (
set {%%x,%%y}=#
)
)


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: The upcoming second part should be equivalent to:
::
:: set row9=%{1,9}%%{2,9}%%{3,9}%%{4,9}%%{5,9}%%{6,9}%%{7,9}%%{8,9}%%{9,9}%
:: set row9=%{1,8}%%{2,8}%%{3,8}%%{4,8}%%{5,8}%%{6,8}%%{7,8}%%{8,8}%%{9,8}%
:: set row7=%{1,7}%%{2,7}%%{3,7}%%{4,7}%%{5,7}%%{6,7}%%{7,7}%%{8,7}%%{9,7}%
:: set row6=%{1,6}%%{2,6}%%{3,6}%%{4,6}%%{5,6}%%{6,6}%%{7,6}%%{8,6}%%{9,6}%
:: set row5=%{1,5}%%{2,5}%%{3,5}%%{4,5}%%{5,5}%%{6,5}%%{7,5}%%{8,5}%%{9,5}%
:: set row4=%{1,4}%%{2,4}%%{3,4}%%{4,4}%%{5,4}%%{6,4}%%{7,4}%%{8,4}%%{9,4}%
:: set row3=%{1,3}%%{2,3}%%{3,3}%%{4,3}%%{5,3}%%{6,3}%%{7,3}%%{8,3}%%{9,3}%
:: set row2=%{1,2}%%{2,2}%%{3,2}%%{4,2}%%{5,2}%%{6,2}%%{7,2}%%{8,2}%%{9,2}%
:: set row1=%{1,1}%%{2,1}%%{3,1}%%{4,1}%%{5,1}%%{6,1}%%{7,1}%%{8,1}%%{9,1}%
::
:: echo %row5%
:: echo %row4%
:: echo %row3%
:: echo %row2%
:: echo %row1%
::
::
:: But obviously, that's a pain in the ass to write out.
:: It uses simple sequences of numbers, so there should be
:: some elegant solution, that would also work for a larger grid.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


for /L %%y IN (9,-1,1) do (
(for /L %%x IN (1,1,9) do (
set tempcoords={%%x,%%y}) && (
set rowtemp=!rowtemp!!tempcoords!
)) && (echo !rowtemp!) && (set rowtemp=)
)

::::::::::::::::::::::::::::::::::::::::::::
:: Now, I can't just wrap {%%x,%%y} in percentage signs, as it
:: contains percentage signs already, and it'd read it as 3 vars -
:: %{% , %x,% , and %y}% .
::
:: Any ideas?
::::::::::::::::::::::::::::::::::::::::::::

pause


See More: Batch - variable inside variable

Report •


#1
April 12, 2009 at 08:13:51
try this:
call set tempcoords=%%{%%x,%%y})%%

Report •
Related Solutions


Ask Question