combining arrays

is there a quick and effecient way of combining 2 dynamic byte arrays? Im willing to try any solution however.
Who is Participating?
VbmasterConnect With a Mentor Commented:

The fastest way to do this is using the CopyMem API, here's a example to add a Byte Array at the end of another Byte Array.

You first need to declare the API in the Declarations part

  Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

And here's the example source code

  Dim a() As Byte
  Dim b() As Byte
  Dim c As Long
  ReDim a(5)
  ReDim b(3)
  For c = 1 To 6
    a(c - 1) = c
  For c = 1 To 4
    b(c - 1) = c * 10
  ReDim Preserve a(5 + 4)
  Call CopyMem(a(6), b(0), 4)
  For c = 0 To UBound(a)
    List1.AddItem a(c)

Some background:

  The API CopyMem takes three parameters. The third parameter is a count of bytes, in the example I want to copy all the items in the Byte Array b, which is 4 bytes. The second parameter is what item to start with. Here I want to start with b(0), then it copies all from b(0) and 4 bytes from there. This will copy all the b array. The first parameter is where to copy it to. I want to add it to the where the a array ended, and that's item with index 6.

  Don't forget to ReDim Preserve the array to where you want to copy, if you don't you will copy over something else, destroying the data that is already there.

  Remember to always double-check the parameters, if you use it wrong you WILL destroy data in the memory and get GPF's but if this API is correctly used it is to enourmous help.

Hope this helps.
tylerdAuthor Commented:
thanks alot! just answer the question now and i'll give you the points
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.