combining arrays

is there a quick and effecient way of combining 2 dynamic byte arrays? Im willing to try any solution however.
thanks
LVL 2
tylerdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
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
  Next
  For c = 1 To 4
    b(c - 1) = c * 10
  Next
 
  ReDim Preserve a(5 + 4)
  Call CopyMem(a(6), b(0), 4)
  For c = 0 To UBound(a)
    List1.AddItem a(c)
  Next
 

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.
0
tylerdAuthor Commented:
thanks alot! just answer the question now and i'll give you the points
0
VbmasterCommented:

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.