Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo Off & Setlocal EnableDelayedExpansion & Title Batch Nested Array & Goto :Main
- :Populate <Element Var Name> <Element Index VarName>
- Set %2=0
- For %%A in (!%1!) Do (
- Set /A "%2+=1"
- Set "%1[!%2!]=%%A"
- )
- Exit /B
- :Main
- REM Define values of variables within array indices (As Examples)
- For %%A in (one,two,three,four,five) Do (
- Set /A %%A=!random! * 1500 / 32768 + 1
- REM Build Array set list for Populate Subroutine. This method of building the set string can be applied to any For Loop.
- If Defined group1 (Set "group1=!group1!,%%A") Else (Set "group1=%%A")
- )
- For %%A in (_One,_Two,_Three,_Four,_Five) Do (
- Set /A %%A=!random! * 1500 / 32768 + 1
- If Defined group2 (Set "group2=!group2!,%%A") Else (Set "group2=%%A")
- )
- Call :Populate group1 _A
- Call :Populate group2 _B
- For %%A in (group1,group2) Do (If Defined Nest (Set "Nest=!Nest!,%%A") Else (Set "Nest=%%A"))
- Call :Populate Nest _C
- Rem Display Array Element Names and Values
- For /L %%A in (1,1,!_A!) Do (For %%B In (!group1[%%A]!) Do (ECHO(group1[%%A] : %%B = !%%B!))
- For /L %%A in (1,1,!_B!) Do (For %%B In (!group2[%%A]!) Do (ECHO(group2[%%A] : %%B = !%%B!))
- REM Accessing Variables from the Nested Array (Every Tier):
- FOR /L %%A in (1,1,!_C!) Do (
- For %%B In (!Nest[%%A]!) Do (
- ECHO(Nest[%%A] : !Nest[%%A]! = !%%B!
- Set count=0
- For %%C In (!%%B!) Do (
- Set /A count+=1
- ECHO(Nest[%%A] : %%B[!count!] = %%C = !%%C!)
- )
- )
- )
- Pause
- Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement