1

In this piece of code I'm trying to make a list fit the screen in WinPE by alternating into two columns. But when I put !modelsvar[%increment%]:~20! in the echo it returns only ~20. Strange because !modelsvar[%%D]:~20! works fine. I've tried many variations of ! and % but no luck. Anyone know if there's is a specific rule that I'm missing?

I have setlocal enabledelayedexpansion enabled

set modelsx=%counter%
set /a counter=0

for /l %%D in (1,2,%modelsx%) do (
set /a counter+=1
set /a increment=!counter!+1
ECHO !counter!. !modelsvar[%%D]:~20!      !increment!. !modelsvar[%increment%]:~20!
set /a counter+=1
)
0

2 Answers 2

1
for /l %%D in (1,2,%modelsx%) do (
   set /a counter+=1
   set /a increment=counter+1
   for %%X in (!increment!) do (
      ECHO !counter!. !modelsvar[%%D]:~20!      !increment!. !modelsvar[%%X]:~20!
   )
   set /a counter+=1
)

Further details at Arrays, linked lists and other data structures in cmd.exe (batch) script

Sign up to request clarification or add additional context in comments.

1 Comment

That works. Thank you. I suspected it had something to do with process order but i didn't think i could echo from two for loops in one line alternatively.
1

You're expanding increment immediately within ECHO, that is like %increment%, so the returned value is the one before the for loop executes.

Here is another work-around:

set modelsx=%counter%
set /a counter=0

for /l %%D in (1,2,%modelsx%) do (
    set /a counter+=1
    set /a increment=!counter!+1
    call ECHO !counter!. !modelsvar[%%D]:~20!      !increment!. %%modelsvar[!increment!]:~20%%
    set /a counter+=1
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.