GetArrayDimensions |
NumberOfDimensions = GetArrayDimensions(ArrayHandle()) |
|
Parameters: ArrayHandle() = The array you wish to get the current number of dimensions from.
|
Returns:
NumberOfDimensions = The number of dimensions in this array |
|
The GetArrayDimensions() allows us to read how many dimensions a particular array has.
FACTS: * The array handle name following the GetArrayDimensions function does not require array indexes, just a pair of closed brackets. i.e Size=GetArrayDimensions(MyArray())
* GetArrayDimensions can be used with any type of array.
* GetArrayDimensions can not be used before the initial dimension statement of an array.
Mini Tutorial #1:
How to display the number of dimensions an array has.
; Create an Array Called MyArray Dim My1DArray(100) Dim My2DArray(100,200) ; Display the number dimensions.. Print GetArrayDimensions(My1DArray()) Print GetArrayDimensions(My2DArray()) ; Show the screen and wait for a key to be pressed Sync WaitKey |
This example would output.
Mini Tutorial #2:
Creating a 2D array and display the Sizes of both Dimensions.
; Create an Array Called GRID() Dim Grid(100,200) ; Display The Number of Dimensions Print GetArrayDimensions(Grid()) ; Loop through each dimension and display it's size For lp =1 To GetArrayDimensions(Grid()) Print GetArrayElements(Grid(),lp) Next ; Display the screen and wait a press to be pressed Sync WaitKey |
This example would output.
Mini Tutorial #3:
Reading the number of dimensiosns of Integer/Floating point/String and Typed Arrays.
; Create an Integer Array Called IntegerArray Dim IntegerArray(100) ; Display The size of the Integer array. Print GetArrayDimensions(IntegerArray()) ; Create an Floating Point Array Called FloatingPointArray Dim FloatingPointArray#(200) ; Display the size of the Floating Point array. Print GetArrayDimensions(FloatingPointArray#()) Dim StringArray$(300) ; Display The size of the String array. Print GetArrayDimensions(StringArray$()) ; Create a Type called POS Type Pos ; define some fields X As Float Y As Float Z As Float EndType ; Create a Array of Type POS Dim TypedArray(400) As Pos ; Display The size of the Typed array. Print GetArrayDimensions(TypedArray().pos) ; Display the screen and wait for a key press Sync WaitKey |
This example would output.
|
|
Example Source: Download This Example ; ========================================== ; GetArrayDimensions EXAMPLE ; ========================================= ; Create an array called "Myarray" Dim MyArray(100) Repeat Cls 0 ; Display The Current Number of Dimensions that MYarray() has Print "Checking The Number of Dimensions of MyArray()" If GetArrayDimensions(MyArray())>0 Print "MyArray() Dimensions:"+Str$(GetArrayDimensions(Myarray())) Print "" ; Display Each Dimensions Size Print "MyArray() Dimensions Sizes:" For lp=1 To GetArrayDimensions(MyArray()) Print Str$(lp)+":"+Str$(GetArrayElements(MyArray(),lp)) Next Else Print "MyArray is not currently Dimensioned" EndIf ; Display Some Controls So The user can Experiment with. Print "" Print "KeyBoard Controls" Print "=================" Print " D = Randomly ReDim MyArray() to be 1D,2D or 3D" Print " U = UnDim the Array" Print " Space = Exit" ; Check if the user has pressed a key. Select Lower$(Inkey$()) ; If the user pressed "d" then Dim the array. Case "d" Select RndRange(1,3) Case 1 Dim MyArray(10) Case 2 Dim MyArray(10,20) Case 3 Dim MyArray(10,20,30) EndSelect ; Check if the user pressed "u" to Undim the array Case "u" UnDim Myarray() EndSelect ; Draw the Screen Sync ; Repeat Until The SpaceKey has been pressed Until SpaceKey() ; END The Program End |
|