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

Samples from Users

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

Array Resize Examples

 Keywords: ArrayRedim ArrayRemove Array Resize Redim Remove Delete Column Row

2010B and newer

;-------------------------------------------------------------------------
; SINGLE DIMENSION - Redim a 1-dim array with 6 elements up to 10 elements
;-------------------------------------------------------------------------
; Allocate a single dimension array with 6 elements:
; a b c d e f

array = Arrayize ("a,b,c,d,e,f", ",")
Pause ('Array Element Count', ArrInfo (array, 1))

; Resize the array to 10 elements.
ArrayRedim (array, 10)
Pause ('Array Element Count', ArrInfo (array, 1))

; Resulting 1-dim array has 10 elements:
; 6 remaining elements from the previous state
; plus 4 new elements of undefined datatype appended.
; a b c d e f --- --- --- ---
;-------------------------------------------------------------------------



;--------------------------------------------------------------------------
; SINGLE DIMENSION - Redim a 1-dim array with 6 elements down to 3 elements
;--------------------------------------------------------------------------
; Allocate a single dimension array with 6 elements:
; a b c d e f

array = Arrayize ("a,b,c,d,e,f", ",")
Pause ('Array Element Count', ArrInfo (array, 1))

; Resize the array to 3 elements.
ArrayRedim (array, 3)
Pause ('Array Element Count', ArrInfo (array, 1))

; Resulting 1-dim array has 3 elements, remaining from the previous state.
; a b c
;--------------------------------------------------------------------------



;------------------------------------------------------------------------------
; TWO DIMENSION - Redim a 2-dim array with 6 x 6 elements up to 10 x 6 elements
;------------------------------------------------------------------------------
; Allocate a two dimensional array with 6 x 6 elements:
; a0 b0 c0 d0 e0 f0
; a1 b1 c1 d1 e1 f1
; a2 b2 c2 d2 e2 f2
; a3 b3 c3 d3 e3 f3
; a4 b4 c4 d4 e4 f4
; a5 b5 c5 d5 e5 f5

array = ArrDimension (6, 6)
For i = 0 To 5
   For k = 0 To 5
      array [i, k] = Num2Char (97 + k) : Num2Char (48 + i)
   Next
Next
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Resize the array to 10 rows, leave number of columns as is.
ArrayRedim (array, 10, -1)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))

; Resulting 2-dim array has 10 x 6 elements:
; 6 remaining rows from the previous state
; plus 4 new rows with 6 elements of undefined datatype appended.
; a0 b0 c0 d0 e0 f0
; a1 b1 c1 d1 e1 f1
; a2 b2 c2 d2 e2 f2
; a3 b3 c3 d3 e3 f3
; a4 b4 c4 d4 e4 f4
; a5 b5 c5 d5 e5 f5
; --- --- --- --- --- ---
; --- --- --- --- --- ---
; --- --- --- --- --- ---
; --- --- --- --- --- ---
;------------------------------------------------------------------------------



;---------------------------------------------------
; SINGLE DIMENSION - Remove a single element
;---------------------------------------------------
; Allocate a single dimension array with 6 elements:
; a b c d e f

array = Arrayize ("a,b,c,d,e,f", ",")
Pause ('Array Element Count', ArrInfo (array, 1))
; Remove the first element. The element "a" will be removed.
ArrayRemove (array, 0)
Pause ('Array Element Count', ArrInfo (array, 1))
; Remove the 3rd element. The element "d" will be removed.
ArrayRemove (array, 2)
Pause ('Array Element Count', ArrInfo (array, 1))
; Remove the last element. The element "f" will be removed.
ArrayRemove (array, ArrInfo (array, 1) - 1)
Pause ('Array Element Count', ArrInfo (array, 1))

; Resulting 1-dim array has 3 elements:
; b c e
;---------------------------------------------------


;-----------------------------------------------------------------------------
; TWO DIMENSION - Remove a row.
;-----------------------------------------------------------------------------
; Allocate a two dimensional array with 6 rows and 6 columns = 6 x 6 elements:
; a0 b0 c0 d0 e0 f0
; a1 b1 c1 d1 e1 f1
; a2 b2 c2 d2 e2 f2
; a3 b3 c3 d3 e3 f3
; a4 b4 c4 d4 e4 f4
; a5 b5 c5 d5 e5 f5

array = ArrDimension (6, 6)
For i = 0 To 5
   For k = 0 To 5
      array [i, k] = Num2Char (97 + k) : Num2Char (48 + i)
   Next
Next
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Remove the first row, from element "a0" to element "f0".
ArrayRemove (array, 0, 1)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Remove the third row, from element "a3" to element "f3".
ArrayRemove (array, 2, 1)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Remove the last row, from element "a5" to element "f5".
ArrayRemove (array, ArrInfo (array, 1) - 1, 1)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))

; Resulting array has 3 rows and 6 columns = 3 x 6 elements:
; a1 b1 c1 d1 e1 f1
; a2 b2 c2 d2 e2 f2
; a4 b4 c4 d4 e4 f4
;-----------------------------------------------------------------------------



;-----------------------------------------------------------------------------
; TWO DIMENSION - Remove a column.
;-----------------------------------------------------------------------------
; Allocate a two dimensional array with 6 rows and 6 columns = 6 x 6 elements:
; a0 b0 c0 d0 e0 f0
; a1 b1 c1 d1 e1 f1
; a2 b2 c2 d2 e2 f2
; a3 b3 c3 d3 e3 f3
; a4 b4 c4 d4 e4 f4
; a5 b5 c5 d5 e5 f5

array = ArrDimension (6, 6)
For i = 0 To 5
   For k = 0 To 5
      array [i, k] = Num2Char (97 + k) : Num2Char (48 + i)
   Next
Next
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Remove the first column, from element "a0" to element "a5".
ArrayRemove (array, 0, 2)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Remove the third column, from element "d0" to element "d5".
ArrayRemove (array, 2, 2)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))
; Remove the last column, from element "f0" to element "f5".
ArrayRemove (array, ArrInfo (array, 2) - 1, 2)
Pause ('Array Element Count', 'Rows: ' : ArrInfo (array, 1) : @CRLF : 'Columns: ' : ArrInfo (array, 2))

; Resulting array has 6 rows and 3 columns = 6 x 3 elements:
; b0 c0 e0
; b1 c1 e1
; b2 c2 e2
; b3 c3 e3
; b4 c4 e4
; b5 c5 e5
;-----------------------------------------------------------------------------

Exit
; Detlev Dalitz.20100717.

Article ID:   W17672
Filename:   Array Resize Examples.txt
File Created: 2011:02:23:12:07:12
Last Updated: 2011:02:23:12:07:12