MoveArray |
MoveArray SourceArray(), DestArray() |
|
Parameters: SourceArray() = The Array you wish to move the data from DestArray() = The Array where you wish the moved data to be placed.
|
Returns: NONE |
|
MoveArray allows us shift the entire contents of the source array into another array. While the source and destination arrays type must match, you can move any type of array you like, including Integer, Floating point, String and type arrays.
The key difference between MoveArray and CopyArray, is that copy creates a duplicate set of data from the source, move shifts the data from the source array into the destination array. After moving the source array will be empty.
FACTS:
* If the destination Array previously contained information, MoveArray will undim that array for you . So any data will be lost.
* After Moving the Source Array will be empty of data.
Mini Tutorial:
In this example, we'll create an array, fill it random values. Then Move this array into another and display them both.
; Create two Arrays... Dim Table(10) Dim TableBackup(0) ; Fill the Table() Array with values from 0 to 10. For lp=0 To 10 Table(lp) =lp Next lp ; Move the entire contents of the Table() array into theTableBackup() array. ; After the move the table() array will be empty. MoveArray Table(),TableBackUp() ; Display the TableBackup array For lp =0 To 10 Print TableBackup(lp) Next ; Show the Disp[lay and wait for a key press Sync WaitKey |
This example will output.
|
|
Example Source: Download This Example ; ======================================== ; MoveArray EXAMPLE ; ======================================== ; Create an Integer Array called "MyArray" containing a random number of elements Dim MyArray(RndRange(1,20)) ; Create an Integer Array called "MyArrayBackUp" containing a random number of elements Dim MyArrayBackup(0) ; Fill MyArray() With random Values FillMyarray() Repeat Cls 0 ; Display the Contents Of the Two Arrays. Print "Array Contents" ShowMyArray("Myarray()",Myarray()) ShowMyArray("MyArrayBackup()",MyArrayBackup()) ; Display Some Controls So The user can Experiment with the Print "" Print "KeyBoard Controls" Print "=================" Print " D = Dim MyArray() to a random size" Print " F = Fill MyArray() with random values" Print " M = Move Myarray() To MyArrayBackup()" Print " R = Move MyArrayBackup() To MyArray()" Print " Space = Exit" ; Check if the user presses a key. Select Lower$(Inkey$()) Case "d" ; If the user Pressed the 'd' key, Then Fill MyArray with random values. Dim MyArray(RndRange(10,30)) Case "f" ; If the user Pressed the 'c' key, Then Fill MyArray with random values. If GetArrayStatus(MyArray())=true FillMyArray() Else Print "MyArray Is Currently Not Defined - Needs to be Dimmed again" Sync Wait 1000 EndIf Case "m" ; If the user pressed the "m" Then move Myarray() into MyArrayBackup() MoveArray Myarray(),MyArrayBackup() ; If the user pressed the "r" Then move MyarrayBack() Back into MyArray() Case "r" MoveArray MyarrayBackUp(),MyArray() 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$)) If GetArrayStatus(thisArray())=true size=GetArrayElements(ThisArray(),1) For lp =0 To size Contents$=Contents$+Digits$(ThisArray(lp),3) If lp<size Then Contents$=Contents$+"," Next Else Contents$="Array Is Not Defined" EndIf Print Contents$ Print "" EndFunction Function FillMyArray() ; Fill MyArray() with Random values between 0 And 1000 If GetArrayStatus(MyArray())=true For lp=0 To GetArrayElements(MyArray(),1) MyArray(lp)=Rnd(1000) Next EndIf EndFunctio |
|