I’m having a problem passing numeric variable, from inside a FOR loop, to a subroutine, and accessing its value.
I’m trying to pass some numeric values to a subroutine, but I’m getting strange results. The value, when passed via CALL does not get updated.
I’ve even tried to enabledelayedexpansion, but hasn’t changed anything. I usually avoid enabling delayed expansion because screws some file names and folders containing & and (). CALLing a subroutine solves the problem. But in this particular case, can’t seem to find an answer.
Following is the troubled code:
<code>@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
CLS
SET /A Index=1
FOR /L %%I IN (1, 1, 11) DO (
CALL :Params %Index% %%I
CALL SET /A Index+=1
)
PAUSE
EXIT
:Params
ECHO %1 %2
EXIT /B
</code>
<code>@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
CLS
SET /A Index=1
FOR /L %%I IN (1, 1, 11) DO (
CALL :Params %Index% %%I
CALL SET /A Index+=1
)
PAUSE
EXIT
:Params
ECHO %1 %2
EXIT /B
</code>
@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
CLS
SET /A Index=1
FOR /L %%I IN (1, 1, 11) DO (
CALL :Params %Index% %%I
CALL SET /A Index+=1
)
PAUSE
EXIT
:Params
ECHO %1 %2
EXIT /B
Run results:
<code>1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
Press any key to continue . . .
</code>
<code>1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
Press any key to continue . . .
</code>
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
Press any key to continue . . .
Any thoughts?
Regards…