I have a little problem and can't get my head to make it work. Here is the code:
SET onts=3
SET port[1]=0
SET port[2]=3
SET port[3]=2
SET free[0]=8
SET free[1]=5
SET free[2]=5
SET free[3]=15
FOR /L %%A IN (1,1,%onts%) DO (
SET /A ont[%%A]=%free[%port[%%A]%]%
)
echo %ont[1]%
echo %ont[2]%
echo %ont[3]%
I expect that code takes on first loop iteration value 0
of variable port[1]
as index and so accessing variable free[0]
to assign its value 8
to variable ont[1]
. On second iteration value 3
of variable port[2]
should be used to get value 15
assigned to variable free[3]
assigned next to variable ont[2]
. And on third iteration the variable ont[3]
should be defined with value 5
from free[2]
after reading value 2
from port[3]
.
So the output should be:
8
15
5
But the batch file outputs:
0
3
2
I've tried using a second variable in loop:
SET /A var1 = %port[%%A]%
SET /A ont[%%A]=%free[%var1%]%
But it didn't work either.
I've also tried calling a function to outsource this code, but still no result - this one I'm not sure, I have perhaps done something wrong.
Has anybody any idea on how to make it work?