WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Arrays
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Add a Row to a Two Dimensional Array

 Keywords: Add Row Element CSV one two dimensional array redim dimension

Question:

I need to quickly add a row to a two dimensional array. I would rather not have to create a new array and copy all of the contents of the old array to the new array. Is there a better option?

Answer:

2010B and newer

Starting in WinBatch 2010B use the function ArrayRedim.
ArrayRedim ( array, sub1, [sub2, [sub3, [sub4, [sub5]]] )

Changes array dimensions in-place while preserving existing content when possible.

"array" array to re-dimension
"sub1" to "sub5" specifies the new "array" dimensions or -1 to keep existing dimensions.

The default for "sub2" through "sub5" is 0 which deletes the existing dimension.
Once an array dimension is set to 0, all subsequent array dimensions must be
set to 0 or omitted.  -1 can also be used  for subsequent dimensions if current
corresponding dimension is already 0.

Returns @True on successful completion.
See Also: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Arrays/Samples~from~Users+Array~Resize~Examples.txt


2010A and older

One trick is to write the two dimensional array out to a temporary file using ArrayFilePutCsv, then use ArrayFileGetCsv and specify the extrarow optional paramater.

For example:

; Add one row to an existing array
tmpfile = "tempfile.tmp"
ArrayFilePutCSV( tmpfile, daArray, @TAB, @TRUE, 0 )
daArray = ArrayFileGetCSV( tmpfile, 1, @TAB, 1 )
FileDelete( tmpfile )

You can also add 1000 rows and 40 columns to a two dimensional array.

tmpfile = "tempfile.tmp"
ArrayFilePutCSV( tmpfile, Array, @TAB, @TRUE, 0 )
Array = ArrayFileGetCSV( tmpfile, 1, @TAB, 1000, 40 )
FileDelete( tmpfile

To add 1000 entries to the one dimensional array:

tmpfile = "tempfile.tmp"
ArrayFilePut( tmpfile, Array, @TRUE )
Array = ArrayFileGet( Array, "?", 1000 )
FileDelete( tmpfile )

Article ID:   W17652
Filename:   Add a Row to a Two Dimensional Array.txt
File Created: 2014:07:18:09:50:32
Last Updated: 2014:07:18:09:50:32