-1

So I got a following piece of code which will set the variable as another variable

  set c1_page_%page_num%=%c1% 
  set c2_page_%page_num%=%c2% 
  set c3_page_%page_num%=%c3% 
  set c4_page_%page_num%=%c4% 
  set c5_page_%page_num%=%c5% 
  set c6_page_%page_num%=%c6% 
  set c7_page_%page_num%=%c7% 
  set c8_page_%page_num%=%c8% 
  set c9_page_%page_num%=%c9% 
  set c10_page_%page_num%=%c10%
  set c11_page_%page_num%=%c11%
  set c12_page_%page_num%=%c12%
  set c13_page_%page_num%=%c13%
  set c14_page_%page_num%=%c14%
  set c15_page_%page_num%=%c15%

I need to somehow still able to set all the variable as another variable with only a single line of code or more. Please help me

Quan
  • 27
  • 2
  • 6
  • The way to deal with this type of variables (called _array_) is described at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Nov 04 '19 at 17:58
  • For example, to set the variables: `for /L %%i in (1,1,15) do set "c%%i_page_%page_num%=!c%%i!"` To show the variables: `for /L %%i in (1,1,15) do echo !c%%i_page_%page_num%!` If you want to vary the value of `page_num` variable _inside_ a FOR loop, you need to use an additional FOR command; for example: `for %%p in (!page_num!) do for /L %%i in (1,1,15) do echo !c%%i_page_%%p!`. Always enclose `%variable%` or `%%i` FOR indices inside `!element!` expansion as described in previous link... – Aacini Nov 04 '19 at 18:22

1 Answers1

3

I am assuming you want a single line that will do the work for you?

@echo off
for /l %%i in (1,1,15) do call set c%%i_page_%page_num%=%%c%%i%%

or using delayedexpansion

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,15) do set c%%i_page_%page_num%=!c%%i!
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Well, here is the full "unfinish" batch file that i am working on: https://pastebin.com/0tAt7DXB – Quan Nov 06 '19 at 14:20
  • Ckeck it out so you can see what am I currently doing and give me an clear answer – Quan Nov 06 '19 at 14:22