endlocal doesn't work on arrays?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Jul 1, 2008
81
0
70
Montreal
#1
TCC 10.00.41 Windows XP [Version 5.1.2600]
This batch file fills a small array
--
setlocal
echo setarray displays %@execstr[setarray]
setarray tablo[4,3]
set cnt=-1
do row = 0 to 3
do col = 0 to 2
set cnt=%@inc[%cnt]
set tablo[%row,%col]=%cnt
enddo
enddo
endlocal
--
and displays
TCC: C:\btm\test1.btm [2] No array variables defined
setarray displays

If I run the batch file again, it displays
setarray displays tablo[4,3]
TCC: C:\btm\test1.btm [3] Array variable is already defined "tablo"

Shouldn't "setlocal" have flushed the the array with the other local variables when the batch file ended? As it is, to clear it I have to "unsetarray tablo" either in the batch file or on the command line.
--
Peter
 

rconn

Administrator
Staff member
May 14, 2008
10,100
85
#2
Peter Bratton wrote:


> Shouldn't "setlocal" have flushed the the array with the
> other local variables when the batch file ended? As it is,
> to clear it I have to "unsetarray tablo" either in the batch
> file or on the command line.

SETLOCAL and ENDLOCAL do not save & restore array variables.

Doing this (particularly with multidimensional arrays) is IMO much more
trouble than it's worth (complex code & a significant slowdown).

Rex Conn
JP Software