#1 16 Nov 2016 23:27

ImAhNoBoDy
Member
Registered: 29 Dec 2015
Posts: 12

Expanding 2 variables at the same time

I'm trying to expand 2 variables at the same time. Is this possible? The issue I'm having is during the IF statement. Instead of echoing 1 and then 2, the script echos 1 and 1.

SETLOCAL ENABLEDELAYEDEXPANSION

SET i=0
SET ARR[%i%]=1
SET /A "i+=1"
SET ARR[%i%]=2
SET /A "i+=1"
SET ARR[%i%]=3
SET ARR

SET len=%i%
SET i=0

IF YO EQU YO (ECHO !ARR[%i%]!
SET /A "i+=1"
ECHO !ARR[%i%]!)

I did try variations of !ARR[!i!]!, ^!ARR[!i!]^!, !ARR[^!I^!]!, and ^!ARR[^!I^!]^! with undesirable results. Anyone can help? Thanks.

Offline

#2 16 Nov 2016 23:51

Aacini
Member
Registered: 05 Dec 2012
Posts: 116

Re: Expanding 2 variables at the same time

I suggest you to carefully read this answer.

Online

#3 17 Nov 2016 00:14

ImAhNoBoDy
Member
Registered: 29 Dec 2015
Posts: 12

Re: Expanding 2 variables at the same time

Aacini wrote:

I suggest you to carefully read this answer.

That was an interesting read and thank you for linking that article. I somewhat understand what the post talked about and was able to complete my script. Thanks Aacini.

SETLOCAL ENABLEDELAYEDEXPANSION

SET i=0
SET ARR[%i%]=1
SET /A "i+=1"
SET ARR[%i%]=2
SET /A "i+=1"
SET ARR[%i%]=3
SET ARR

SET len=%i%
SET i=0

IF YO EQU YO (ECHO !ARR[%i%]!
SET /A "i+=1"
call ECHO %%ARR[!i!]%%
SET /A "i+=1"
call ECHO %%ARR[!i!]%%)

Offline

#4 17 Nov 2016 03:35

Aacini
Member
Registered: 05 Dec 2012
Posts: 116

Re: Expanding 2 variables at the same time

May I ask you to upvote such S.O. answer? It just needs 4 upvotes more to accumulate 100!

Online

#5 17 Nov 2016 04:19

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 142

Re: Expanding 2 variables at the same time

Aacini wrote:

May I ask you to upvote such S.O. answer? It just needs 4 upvotes more to accumulate 100!

3

Offline

Board footer

Powered by FluxBB