Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Copying Question 2

Status
Not open for further replies.

Jdoggers

Technical User
Feb 20, 2005
43
US
Hi,
Is there any way to copy an array to another array of the same size as long as they are both defined the same. Oh, I would not like to use loops or using a variant type array for the second one recieving the data. Any way to do this? thanks
 
Dim array1(3) As String
Dim array2() As String

array1(2) = "Test"
array2 = array1
MsgBox array2(2)


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
If your destination array is a dynamic array, then you can simply copy the source array to destination using a simple assingment. Otherwise, you can use the CopyMemory function to copy an array to a fixed array.
___
[tt]
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
Dim A(5) As Long, N As Long
Dim B() As Long 'dynamic array
Dim C(5) As Long 'fixed array
'fill the source array
For N = 0 To 5
A(N) = N
Next

'copy A to B
B = A
'copy A to C
CopyMemory C(0), A(0), 24 'size of the array
End Sub[/tt]
___

See also thread711-763982.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top