Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

endlocal doesn't work on arrays?

Jul
81
0
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
 
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
 

Similar threads

Back
Top