GetArrayElements |
Size = GetArrayElements(Array(), [Dimension =1]) |
|
Parameters: Array() = The array you wish to query [Dimension =1] = The Optional Index of the Dimension you want to get the size of. It defaults to the first dimension.
|
Returns:
Size = Returns the number the elements within an array dimension |
|
The GetArrayElements function returns the current size (in cells/elements) of an array dimension. It can be used with any dynamic type of array (Integer, Floats#, String$, Typed) of any number of dimensions.
FACTS:
* The array handle(name) following the GetArrayElements function does not require array indexes, just a pair of closed brackets. i.e Size=GetArrayElements(MyArray(),1)
* GetArrayElements can not be used before the initial dimension statement of the array.
* GetArrayElements doesn't support static array fields in user defined type structures, they're not dynamic arrays !
Mini Tutorial:
Reading the current size of a 1D array.
; Create an Array Called MyArray Dim MyArray(100) ; Display The SIZE of the first dimension.. Print GetArrayElements(MyArray(),1) ; Display the Screen and wait for a key press Sync WaitKey |
Creates a 2D array and displays the size of both Dimensions.
; Create an Array Called MyGrid Dim MyGrid(100,200) ; Display The SIZE of the first dimension.. Print GetArrayElements(MyGrid(),1) ; Display The SIZE of the second dimension.. Print GetArrayElements(MyGrid(),2) ; Display the Screen and wait for a key press Sync WaitKey |
Reading the size of Integer/Float/String and Typed Arrays.
; Create an Integer Array Called MyArray Dim IntegerArray(100) ; Display The size of the Integer array. Print GetArrayElements(IntegerArray(),1) Dim FloatingPointArray#(200) ; Display The size of the Floating Point array. Print GetArrayElements(FloatingPointArray#(),1) Dim StringArray$(300) ; Display The size of the String array. Print GetArrayElements(StringArray$(),1) ; Create a Type called POS Type Pos 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 GetArrayElements(TypedArray().pos,1) ; Display the Screen and wait for a key press Sync WaitKey |
|
|
Example Source: Download This Example ; ======================================== ; GetArrayElements EXAMPLE ; ======================================== ; Create an Integer Array called "MyArray" containing a random number of elements Dim MyArray(RndRange(1,20)) ; Call the Function to fill this array FillMyarray() Repeat Cls 0 ; Display The Current STATUS and SIZE of MyARRAY() Print "Checking The Size of MyArray()" Print "MyArray() Size:"+Str$(GetArrayElements(Myarray(),1)) Print "" ; Check the Current Status of MyArray() If GetArrayStatus(MyArray()) = true ; Array Exists so Display a Message And show the arrays contents Print "Array Contents" Print "" ShowMyArray() EndIf ; Display Some Controls So The user can Experiment with the Print "" Print "KeyBoard Controls" Print "=================" Print " N = Create a MyArray() And fill it with values" Print " Space = Exit" Select Lower$(Inkey$()) Case "n" ; If the user Pressed the 'D' key, Then Dim MyArray To it's new size Dim MyArray(RndRange(1,20)) FillMyArray() EndSelect ; Draw the Screen Sync ; Repeat Until The SpaceKey has been pressed Until SpaceKey() ; END The Program End Function ShowMyArray() ; Compile the contents of our the MyArray into a String And display them. Print "Contents of MYARRAY()" Print "---------------------" size=GetArrayElements(Myarray(),1) For lp =0 To size Contents$=Contents$+Digits$(MyArray(lp),3) If lp<size Then Contents$=Contents$+"," Next Print Contents$ Print "" EndFunction Function FillMyArray() ; Fill MyArray() with Random values between 0 And 1000 For lp=0 To GetArrayElements(MyArray(),1) MyArray(lp)=Rnd(1000) Next EndFunction |
|