Copying one array to another

  • Thread starter Thread starter max
  • Start date Start date
M

max

How do I copy all the contents of one array to another? eg

DestinationArrey()=OriginalArray()

Cant seen to get the syntax right
Please help.
 
max said:
How do I copy all the contents of one array to another? eg

DestinationArrey()=OriginalArray()

Cant seen to get the syntax right
Please help.

It would depend on how the arrays are declared. If both declarations
are specific as to bounds ...

Dim OriginalArray(10) As <type>
Dim DestinationArray(10) As <type>

.... then I think your only recourse is to loop through the elements of
the arrays and assign them one by one:

Dim I As Integer

For I = LBound(OriginalArray) To UBound(OriginalArray)
DestinationArray(I) = OriginalArray(I)
Next I

However, if the destination array is declared as dynamic ...

Dim DestinationArray() As <type>

then you can write the following assignment statement:

DestinationArray = OriginalArray

That seems to copy all of OriginalArray to DestinationArray.
 
I suggest something like the following:
Dim OrigArray() as Integer(or String or Variant, etc.)
Dim DestArray() as Integer
Dim intI as Integer

' fill your original array (example)
ReDim OrigArray(20)
For intI = 0 to 20 ' 21 elements
OrigArray(intI) = intI
Next intI
' redimension your destination array to fit the original
array
ReDim DestArray(Ubound(OrigArray, 1))
' copy the array
For intI = 0 to Ubound(OrigArray, 1)
DestArray(intI) = OrigArray(intI)
Next intI
 
Hi,

In the old days, we used the hmemcpy API for that, but I see that it's been
replaced by the RtlCopyMemory API.
 
Back
Top