Performs in-place insertion of an element into a single dimension array, or the in-place insertion of a row or column into a two dimension array.
ArrayInsert( array, sub [, dim [, value]] )
(a) array: specifies an array.
(i) sub: subscript of the element to insert into single dimension array. Subscript of the row or column to insert into a two dimension array..
(i) dim: [optional] must be 1 or omitted for single dimension arrays. Must be either 1 to insert an array row or 2 to insert an array column into a two dimension array.
(u/s/i/f/a) value: [optional] initial value of inserted element(s).
(i) returns @True.
Multidimensional arrays in WinBatch use 'Row Major' format. For Example: arrMyArray[ row_index , column_index ]
Note: Arrays can not be used in the value parameter when inserting an entire row or column into another array.
;***************************************************************************
;**
;** Insert an Element into a one Dimensional Array
;**
;***************************************************************************
strList = 'a b c A B C 1 0 -1' value = 'D' ; (uppercase letter D) ; Create an array to Insert data arrList = Arrayize( strList, ' ' ) ; insert value in the array result = ArrayInsert(arrList,6,1,value) strNewList = ArrayToStr(arrList) ; Display results Pause( 'ArrayInsert of value: ' : value, strNewList) Exit
;*************************************************************************** ;** ;** Insert a Row into a two Dimensional Array ;** ;*************************************************************************** ; Dynamically create a two dimensional array from CSV data ; using the FilePut & ArrayFilePutCSV trick data = 'A0,A1,A2,A3':@LF:'B0,B1,B2,B3':@LF:'D0,D1,D2,D3':@LF:'E0,E1,E2,E3' ; missing row C tmpfile = "tempfile.tmp" FilePut( tmpfile, data ) arrA = ArrayFileGetCSV( tmpfile, 1) FileDelete( tmpfile )
; Now insert a blank row into arrA row = 2 ;third row rowflag = 1 initval = "" ArrayInsert( arrA, row, rowflag, initval )
; Define row data in an seperate 1 - dimensional array newdata = 'C0,C1,C2,C3' arrB = Arrayize( newdata, ',' )
; Insert arrB data into arrA For element = 0 To ArrInfo( arrB, 1 )-1 arrA[row,element] = arrB[element] Next
; Display Results MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`ArrayInsert Row` MyDialogX=002 MyDialogY=059 MyDialogWidth=438 MyDialogHeight=195 MyDialogNumControls=003 MyDialogProcedure=`DEFAULT` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`157,165,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`217,165,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`013,011,402,142,REPORTVIEW,"ReportView_1",arrA,DEFAULT,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") Exit
;*************************************************************************** ;** ;** Insert a column into a two Dimensional Array ;** ;*************************************************************************** ; Dynamically create a two dimensional array from CSV data ; using the FilePut & ArrayFilePutCSV trick data = 'A0,A1,A3':@LF:'B0,B1,B3':@LF:'C0,C1,C3':@LF:'D0,D1,D3' ; missing column 2 tmpfile = "tempfile.tmp" FilePut( tmpfile, data ) arrA = ArrayFileGetCSV( tmpfile, 1) FileDelete( tmpfile )
; Now insert a blank column into arrA col = 2 ;third column colflag = 2 initval = "" ArrayInsert( arrA, col, colflag, initval )
; Define column data in an seperate 1 - dimensional array newdata = 'A2,B2,C2,D2' arrB = Arrayize(newdata, ',')
; Insert arrB data into arrA For element = 0 To ArrInfo( arrB, 1 )-1 arrA[element,col] = arrB[element] Next
; Display Results MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`ArrayInsert Row` MyDialogX=002 MyDialogY=059 MyDialogWidth=438 MyDialogHeight=195 MyDialogNumControls=003 MyDialogProcedure=`DEFAULT` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`157,165,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`217,165,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`013,011,402,142,REPORTVIEW,"ReportView_1",arrA,DEFAULT,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") Exit
Arrays, ArrayFileGet, ArrayFileGetCsv, ArrayFilePut, ArrayFilePutCsv, ArrayFromStr, ArrayInsert, ArrayItemize, Arrayize, ArrayLocate, ArrayRedim, ArrayRemove, ArrayReverse, ArraySearch, ArraySort, ArraySwapElements, ArrayToStr, ArrDimension, ArrInfo, ArrInitalize, Drop