GetArrayStatus |
StateFlag = GetArrayStatus(CheckThisArray()) |
|
Parameters: CheckThisArray() = The array name you wish to check the dimension state of
|
Returns:
StateFlag = Returns a TRUE/FALSE value |
|
GetArrayStatus allows us to check if a dimensioned array has data in it or not. The function will return a one (TRUE) if the array has been dimensioned previously (filled with data), otherwise it'll return a zero (false). You can use the GetArrayElements and GetArrayDimensions functions to query the array further.
FACTS:
* The array handle/name following the GetArrayStatus function does not require array indexes, just a pair of closed brackets. i.e Status=GetArrayStatus(MyArray())
* GetArrayStatus can not be used before the initial dimension statement of the array.
Mini Tutorial:
Creating an array and displaying it's status..
; Create an Array Called MyArray Dim MyArray(100) ; Display it's status.. Since it's just been dimmed, it will return a TRUE value of one. Print GetArrayStatus(MyArray()) ; Release this array from memory UnDim MyArray() ; Display it's status.. Now it'll return a FALSE. Print GetArrayStatus(MyArray()) ; Display the Screen and wait for the user to press a key Sync WaitKey |
This example would output.
|
|
Example Source: Download This Example ; ====================================== ; GetArrayStatus EXAMPLE by Kevin Picone ; ====================================== Size=10 ; Create an Integer Array called "MyArray" containing 10 elements Dim MyArray(Size) FillMyArray(size) Repeat Cls 0 ; Display The Current STATUS and SIZE of MyARRAY() Print "Checking The Status of MyArray()" Print "Status:"+Str$(GetArrayStatus(MyArray())) Print "Size:"+Str$(Size) Print "" ; Check the Current Status of MyArray() If GetArrayStatus(MyArray()) = true ; Array Exists so Display a Message And show the arrays contents Print "Yes MyArray() has been dimmed And is ready for use" Print "" ShowMyArray(Size) Else ; No MyArray Doesn't Exist so Display a Message Print "No MyArray() is Empty And is not ready for use" EndIf ; Display Some Controls So The user can Experiment with the Print "" Print "KeyBoard Controls" Print " D = Dim MyArray() with a new random size (destorys previous contents)" Print " R = ReDim MyArray() with a new random size (protects pervious contents)" Print " U = UnDim MyArray()" Print " F = Fill MyArray() with a random numbers" Print "Space To Exit" Select Lower$(Inkey$()) Case "d" ; If the user Pressed the 'D' key, Then Dim MyArray to it's new size size=RndRange(1,20) Dim MyArray(size) Case "r" ; If the user Presses the 'R' key, Then ReDim MyArray to it's new size If GetArrayStatus(MyArray())=true size=RndRange(1,20) ReDim MyArray(size) Else Print "Error - MyArray Must be Dimmed before it can be Redimmed" Sync Wait 1000 EndIf Case "f" ; If the user Presses the 'F' key, Then FILL MyArray with random numbers FillMyArray(size) Case "u" ; If the user presses the "U" key, then UNDIM (delete) this arrays memory. size=0 UnDim MyArray() EndSelect ; Draw the Screen Sync ; Repeat Until The SpaceKey has been pressed Until SpaceKey() ; END The Program End Function ShowMyArray(Size) ; Compile the contents of our the MyArray into a String and display them. Print "Contents of MYARRAY()" Print "---------------------" For lp =0 To size Contents$=Contents$+Digits$(MyArray(lp),3) If lp<size Then Contents$=Contents$+"," Next Print Contents$ Print "" EndFunction Function FillMyArray(Size) ; Fill MyArray() with Random values between 0 And 1000 For lp=0 To Size MyArray(lp)=Rnd(1000) Next EndFunction |
|