ClearArray |
ClearArray SourceArray(), FillValue |
|
Parameters: SourceArray() = The Array you wish to clear FillValue = The Value or String you wish to fill this array with.
|
Returns: NONE |
|
ClearArray fills an entire array with either a value or a string. You can use clear array on any type of array. Including Integer, floating point, String and Type Arrays also. However the type of FillValue must match the type of the array you wish to fill.
FACTS:
* ClearArray can be used upon Integer, Floating Point, String and Type arrays.
Mini Tutorial #1:
Filling an Integer Array with the value 1000.
; Create an Array... Dim Table(10) ; Fill theTable() Array with the Value 1000 ClearArray Table(),1000 ; Display the table() array For lp =0 To 10 Print Table(lp) Next ; Show the Display and wait for a key press Sync WaitKey |
Mini Tutorial #2:
Filling a STRING Array with the string "Hello World"
; Create a string array... Dim StringTable$(10) ; Fill the StringTable() Array with "Hello World" ClearArray StringTable$(),"Hello World" ; Display the StringTable$() array For lp =0 To 10 Print StringTable$(lp) Next ; Show the Display and wait for a key press Sync WaitKey |
Mini Tutorial #3:
Filling a TYPED Arrays. Cleararray will ingore any fill parameter, and simply delete any instances within the array.
; Create a Type called pos, with the fields X,Y,Z Type Pos x,y,z EndType Dim Table(10) As pos ; Fill the array with random values For lp=0 To GetArrayElements(Table().pos,1) Table(lp).x= Rnd(100) Table(lp).y= Rnd(100) Table(lp).z= Rnd(100) Print Str$(table(lp).x)+", "+Str$(table(lp).y)+", "+Str$(table(lp).z) Next ; Clear the Array.. ClearArray Table().pos, null ; Display the Array For lp=0 To GetArrayElements(Table().pos,1) Print Str$(table(lp).x)+", "+Str$(table(lp).y)+", "+Str$(table(lp).z) Next ; Show the Display and wait for a key press Sync WaitKey |
|
|
Example Source: Download This Example ; ======================================== ; ClearArray EXAMPLE ; ======================================== ; Create an Integer Array called "MyArray" containing 20 elements Dim MyArray(20) ; Limit the Speed of the demo to a max of 20 Frames Per Second, so we ; can see whats going on. SetFPS 20 ; Start a REpeat/Until Repeat ; Clear The Screen to black Cls 0 ; Randomly Put a Value Into the Myarray() Array MyArray(Rnd(GetArrayElements(MyArray(),1)))=Rnd(100) ; Display the Contents Of MyArray() Print "Array Contents" ShowMyArray("Myarray()",Myarray()) ; Display Some Controls So The user can Experiment with the Print "" Print "KeyBoard Controls" Print "=================" Print " C = Clear MyArray() with a value of zero" Print " Space = Exit" ; Check Select Lower$(Inkey$()) Case "c" ; If the user Pressed the 'c' key, Then Fill MyArray with A random value. ClearArray MyArray(),0 EndSelect ; Draw the Screen Sync ; Repeat Until The SpaceKey has been pressed Until SpaceKey() ; END The Program End Function ShowMyArray(Message$,ThisArray()) ; Compile the contents of our the MyArray into a String And display them. Print "" Print Message$ Print Make$("-",Len(message$)) size=GetArrayElements(ThisArray(),1) For lp =0 To size Contents$=Contents$+Digits$(ThisArray(lp),3)+"," Next Print TrimRight$(Contents$,",") Print "" EndFunction |
|