If you have a known number of dimensions, known data type, and in-line code, the loop within a loop method is common-place. If, however, you are working inside of function or subroutine and the array is passed in as an argument, you will need to use the array access functions:
"function dims( var a as array ) as int" "function dimLimit( n as int, var a as array ) as int" "function elementType( var a as array ) as string"
"function intElement( var a as array, ... as int ) as int" "function doubleElement( var a as array, ... as int ) as double" "function moneyElement( var a as array, ... as int ) as money" "function booleanElement( var a as array, ... as int ) as boolean" "function charElement( var a as array, ... as int ) as char" "function dateElement( var a as array, ... as int ) as date" "function timeElement( var a as array, ... as int ) as time" "function stringElement( var a as array, ... as int ) as string"
"subroutine setIntElement( newValue as int, var a as array, ... as int )" "subroutine setDoubleElement( newValue as double, var a as array, ... as int )" "subroutine setMoneyElement( newValue as money, var a as array, ... as int )" "subroutine setBooleanElement( newValue as boolean, var a as array, ... as int )" "subroutine setCharElement( newValue as char, var a as array, ... as int )" "subroutine setDateElement( newValue as date, var a as array, ... as int )" "subroutine setTimeElement( newValue as time, var a as array, ... as int )" "subroutine setStringElement( newValue as string, var a as array, ... as int )"
These allow you to access arrays without having to pass in the number of dimensions or even the data type of the array. You could write a single subroutine that "empties" (I assume you mean initializes) all of your arrays.
If you have a need for truly arbitrary dimensions, I recommend that you consider using a one dimensional array, and use read and write access functions that "flatten" the additional dimensions:
2D: position = (width * y) + x
3D: position = (height * width * z) + (width * y) + x;
etc...
If you use an array to hold the boundaries for each dimension, you can literally create an array as many dimensions as your memory capacity will allow.
|