skip to main content

kiesler.at

Frequently Asked Questions

View Suggest a FAQ  


The ad will go away if you log in.


Q:   Number of elements in an array?

A: use the custom user-defined function GetArraySize ((KB 139)).

For multi-dimensional arrays, if you need to know how many rows, columns, etc. are in the array, you will need to use a modified version of the GetArraySize function.

Example:
public function GetArraySize(inout Arr[], out row_count, out col_count)
{
auto i, res[];
auto row,col;
row = 0;
col = 0;
for (i in Arr)
{
# Split on special character that separates the array subscript elements.
split(i,res,"");
if(res[1] > row)
row = res[1];
if(res[2] > col)
col = res[2];
}
row_count = row + 1;
col_count = col + 1;
}

Example:
array[0,0] = "1";
array[0,1] = "2";
array[0,2] = "3";
array[1,0] = "1";
array[1,1] = "2";
array[1,2] = "3";
array[2,0] = "1";
array[2,1] = "2";
array[2,2] = "3";

rc = GetArraySize (array, rows, cols);
pause("The array has " rows " rows and " cols " columns");



How helpful was this FAQ?




RSSComments - Make a comment
The comments are owned by the poster. We are not responsible for its content.