1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

endlocal doesn't work on arrays?

Discussion in 'Support' started by Peter Bratton, Jan 25, 2009.

  1. Peter Bratton

    Joined:
    Jul 1, 2008
    Messages:
    81
    Likes Received:
    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
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,729
    Likes Received:
    80
    Peter Bratton wrote:


    > 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
     

Share This Page