Code: Select all

```
SET var[1]=12
SET var[2]=23
```

Code: Select all

`SET displayvar=%var[#]%`

Code: Select all

`SET /A var=%displayvar:#=1%`

Any tips or guidance would be much appreciated.

Thanks in advance, Lowsun

**Moderator:** DosItHelp

Sorry about the confusing title, but I couldn't think about any other way to word it. Basically, I have some variables, for example:

And another one, which contains the "var" prefix, but not that specific number, like:

I'm trying to use it like:
To hopefully get the value of %var[1]%, but obviously it's already been expanded when it was SET above, so it gives nothing. I've tried doubling the %% and using CALL SET, but so far to no avail. Using DELAYEDEXPANSION isn't an option either, since I'm substituting variables with delayed expansion already.

Any tips or guidance would be much appreciated.

Thanks in advance, Lowsun

Code: Select all

```
SET var[1]=12
SET var[2]=23
```

Code: Select all

`SET displayvar=%var[#]%`

Code: Select all

`SET /A var=%displayvar:#=1%`

Any tips or guidance would be much appreciated.

Thanks in advance, Lowsun

Code: Select all

```
setlocal enabledelayedexpansion
SET var[1]=12
SET var[2]=23
set #=1
SET displayvar=!var[%#%]!
set displayvar
```

Code: Select all

```
setlocal
SET var[1]=12
SET var[2]=23
set #=1
call SET displayvar=%%var[%#%]%%
set displayvar
```

(Why the extra complication?)

Code: Select all

```
setlocal
SET var[1]=12
SET var[2]=23
set step1=%%var[#]%%
set step2=%step1:#=1%
call set display=%step2%
set step
set display
```

Your technique can work if you simply define displayvar properly. It works because SET /A can expand a variable on its own.\
--OUTPUT--
But why on earth are you structuring things this way

Code: Select all

```
@echo off
setlocal
SET var[1]=12
SET var[2]=23
set "displayvar=var[#]"
set /a var=%displayvar:#=1%
echo %var%
```

Code: Select all

```
12
```

Thanks Eureka and dbenham. I ended reworking all the code I was doing, since it was getting unwieldy down the line. Turns out I was over complicating a lot of stuff. But thanks for taking the time help