- May
- 3,515
- 4
What is the syntax by which commands in a batch file can access the elements
of an array when the name of the array is the first of the calling
parameters of the batch file?
Example:
--- file caller.btm ---
setarray myarray[1,2,3,4]
call xyz.btm myarray
--- end of file caller.btm ---
--- file xyz.btm ---
echo array %1
for /l %n in (0,1,5) echo %n %@arrayinfo[%1,%n]
switch %@arrayinfo[%1,0]
case 1
echo %1[0]
case 2
echo %1[0,0]
case 3
echo %1[0,0,0]
case 4
echo %1[0,0,0,0]
endswitch
quit
--- end of file xyz.btm ---
In the above example, I also tried %[1[0]] and %[%1[0]] in lieu of %1[0].
Note: I came across this problem when I tried to write a batch file to
perform the reverse of the function @filearray, i.e., to write the contents
of an array to a file.
--
Steve
of an array when the name of the array is the first of the calling
parameters of the batch file?
Example:
--- file caller.btm ---
setarray myarray[1,2,3,4]
call xyz.btm myarray
--- end of file caller.btm ---
--- file xyz.btm ---
echo array %1
for /l %n in (0,1,5) echo %n %@arrayinfo[%1,%n]
switch %@arrayinfo[%1,0]
case 1
echo %1[0]
case 2
echo %1[0,0]
case 3
echo %1[0,0,0]
case 4
echo %1[0,0,0,0]
endswitch
quit
--- end of file xyz.btm ---
In the above example, I also tried %[1[0]] and %[%1[0]] in lieu of %1[0].
Note: I came across this problem when I tried to write a batch file to
perform the reverse of the function @filearray, i.e., to write the contents
of an array to a file.
--
Steve