Hello,
the documentation about the order of rows,cols in setarray confuses me:
It says: You can define up to 4-dimensional arrays. For example, to define a 5-row by 10-column array:
BTW: Its documented like this in TCMD 22.0, 25.0 and 28.0.
In my case I would like to have a 2-dimensional array with 4-rows (datasets) by 2-columns (Name, eMail). The following drawing illustrates the structure and my understanding of a two-dimensional array.
In fact, I have to define the array exactly the oposite way (cols,rows) to make it work!
Gives the following output (as expected):
Or do I have a wrong understanding how does TCC arrange a two dimensional array?
the documentation about the order of rows,cols in setarray confuses me:
It says: You can define up to 4-dimensional arrays. For example, to define a 5-row by 10-column array:
Code:
setarray array1[5,10]
BTW: Its documented like this in TCMD 22.0, 25.0 and 28.0.
In my case I would like to have a 2-dimensional array with 4-rows (datasets) by 2-columns (Name, eMail). The following drawing illustrates the structure and my understanding of a two-dimensional array.
Code:
+------------------------------+-------------------------+
| Index | 1st dimension (Name) | 2nd dimension (eMail) |
+-------+----------------------+-------------------------+
| 0 | Alice | [email protected] |
| 1 | Bob | [email protected] |
| 2 | Barney | [email protected] |
| 3 | Fred | [email protected] |
+-------+----------------------+-------------------------+
In fact, I have to define the array exactly the oposite way (cols,rows) to make it work!
Code:
@ECHO OFF
CLS
setarray /T:5 array[2,4]
:: Declaring values for the first dimension (i. e. Name)
set array[0,0]=Alice
echo %array[0,0]
set array[0,1]=Bob
echo %array[0,1]
set array[0,2]=Barney
echo %array[0,2]
set array[0,3]=Fred
echo %array[0,3]
:: Declaring values for the second dimension (i. e. eMail)
set array[1,0][email protected]
echo %array[0,0] = %array[1,0]
set array[1,1][email protected]
echo %array[0,1] = %array[1,1]
set array[1,2][email protected]
echo %array[0,2] = %array[1,2]
set array[1,3][email protected]
echo %array[0,3] = %array[1,3]
ECHO.
ECHO Number of dimensions of Array: %@arrayinfo[array,0]
ECHO Number of elements in the 1st-dimension of the array: %@arrayinfo[array,1]
ECHO Number of elements in the 2nd-dimension of the array: %@arrayinfo[array,2]
ECHO Total number of elements in the array: %@arrayinfo[array,5]
ECHO.
DO i=0 to %@DEC[%@arrayinfo[array,2]]
ECHO Value of ^%i: %i - %array[0,%i] %array[1,%i]
ENDDO
unsetarray array
Gives the following output (as expected):
Code:
Alice
Bob
Barney
Fred
Alice = [email protected]
Bob = [email protected]
Barney = [email protected]
Fred = [email protected]
Number of dimensions of Array: 2
Number of elements in the 1st-dimension of the array: 2
Number of elements in the 2nd-dimension of the array: 4
Total number of elements in the array: 8
Value of %i: 0 - Alice [email protected]
Value of %i: 1 - Bob [email protected]
Value of %i: 2 - Barney [email protected]
Value of %i: 3 - Fred [email protected]
Or do I have a wrong understanding how does TCC arrange a two dimensional array?