CopyArrayCells
CopyArrayCells SourceArray(), SrcStartElement, SrcElementDelta, DestArray(), DestElement, DestElementDelta, Length
 
Parameters:

    SourceArray() = The Array you wish to copy
    SrcStartElement = The address of starting element
    SrcElementDelta = The difference between elements
    DestArray() = The Array where you wish the copied data be placed.
    DestElement = The address of starting element in the destination array
    DestElementDelta = The difference between destination elements
    Length = The number of the elements to copy
Returns: NONE
 

CopyArrayCells will copy a selection of elements (cells) from one array into another.

While the source and destination arrays must be of the same type, you can copy any type of array you wish, including Integer, Floating point, Strings and even Typed arrays. This can save the programmer having to manually move information.





FACTS:


* If the destination array previously contained information, CopyArray will undim the destination and then clone the Source data into the Destination.

* CopyArrayCells can be used upon Integer, Floating Point, String and Type arrays.





Mini Tutorial #1:


In this simple example, we'll create an integer array, fill it random values. Then transfer this array into another using Copyrray and then display them both together.

  
  
; Create two Arrays...
  Dim Table(10)
  Dim TableBackup(10)
  
; Fill the Table() Array with some random numbers
  Print "Table 1"
  For lp=0 To 10
     Table(lp) =Rnd(1000)
     Print Str$(lp)+":"+Str$(Table(lp))
  Next lp
  
; Copy the last half of Table() into the
; top of the TableBackup() array.
  CopyArrayCells Table(),10,-1,TableBackup(),0,1,5
  
  
; Display TableBackup() array
  Print ""
  Print "Table Backup Array"
  For lp =0 To 10
     Print Str$(lp)+":"+Str$(TableBackup(lp))
  Next
  
  
; Show the Display and wait for a key press
  Sync
  WaitKey
  
  


This example would output something like this.

  
  Table 1
  0:543
  1:999
  2:12
  3:300
  4:22
  5:733
  6:76
  7:203
  8:999
  9:78
  10:444
  
  Table Backup Array
  0:444
  1:78
  2:999
  3:203
  4:75
  5:0
  6:0
  7:0
  8:0
  9:0
  10:0
  
  






Mini Tutorial #2:


In this simple example, we'll create two typed arrays, fill one with random values. Then transfer the first 5 type elements from the Mydata1 into another using CopyArrayCells and then display the copy. The elements are copied




  
; Declare a type
  Type Pos
     X,y,z
  EndType
  
; Dim two typed arrays
  Dim MyData1(10As pos
  Dim MyData2(10As pos
  
; Fill MyData1() with some random data
  Print "Data in MyData Array #1"
  For lp =0 To GetArrayElements(MyData1().pos,1)
     MyData1(lp).x =Rnd(100)
     MyData1(lp).y =Rnd(100)
     MyData1(lp).z =Rnd(100)
     Print Str$(mYdata1(lp).x)+","+Str$(mYdata1(lp).y)+","+Str$(mYdata1(lp).z)
  Next
  
; Copy some of the cells from the MyData1() tp MyData2()
  CopyArrayCells MyData1().pos, 0,1,MyData2().pos,1,2,5
  
  Print "Data in MyData Array #2"
  For lp =0 To GetArrayElements(MyData2().pos,1)
     Print Str$(MyData2(lp).x)+","+Str$(MyData2(lp).y)+","+Str$(MyData2(lp).z)
  Next
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  


This example would output something like this.

  
  Data in MyData Array #1
  91,57,42
  5,68,20
  21,2,21
  65,69,93
  97,89,94
  40,14,11
  22,18,89
  19,79,7
  64,48,17
  63,92,22
  26,41,25
  Data in MyData Array #2
  0,0,0
  91,57,42
  0,0,0
  5,68,20
  0,0,0
  21,2,21
  0,0,0
  65,69,93
  0,0,0
  97,89,94
  0,0,0
  


 
Related Info: CopyArray | CopyMemory | getArrayPtr | MoveArray | SwapArray :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com