vb.net combine two byte arrays

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi.

I used to be able to do this easily in vb 6 via looping and preserving
the source array data/size etc.


How can I do this in vb.net? I've been trying for a while now and this
should be an easy task but it just isn't clicking.

For some reason, the preserve doesn't seem to be working.

I have a function where I pass it the source array of bytes and
destination array of bytes and it is to combine them.

CompletedFile is the array to hold the two combined byte arrays and is
used as the destination in the function call:

CompletedFile = Me.CombineByteArray(SourceFile, CompletedFile)

Private Function CombineByteArray(ByVal Source() As Byte, ByVal
Destination() As Byte) As Byte()
Dim intCurrPosition As Integer
Dim i As Integer

intCurrPosition = Destination.Length - 1

ReDim Preserve Destination(Destination.Length + Source.Length)
Try
For i = 0 To Source.Length - 1
Destination(intCurrPosition) = Source(i)
intCurrPosition = intCurrPosition + 1
Next
Return Destination
Catch ex As Exception

End Try


End Function


The above code is keeping the first byte array and not combining the
second byte array even though there are no errors.

Any ideas?

Justin

.



Relevant Pages

  • Re: Linked workbooks, how to with arrays?
    ... Assume a source array in A1:C8 ... Select an identical 8R x 3C grid ... The same formula will appear in each cell in B1:D8 ...
    (microsoft.public.excel.misc)
  • Re: Is it Possible to write a section of a byte array to a file?
    ... "So, it looks like you can use MidB to slice data out of a Byte array, ... MidB gives access to *all* bytes in the source byte array, no matter what the starting index of the source array is. ...
    (microsoft.public.vb.general.discussion)
  • Re: Randomize a one dimentional array
    ... Copy the items in random order from the source array to a second array. ... REDIM PRESERVE source ...
    (microsoft.public.scripting.vbscript)
  • Re: application.match and multidimensional array?
    ... I'm using several arrays in code; the smaller array keeps a subset ... latter would end up including every element from the source array. ... I'm going through up to 10 iterations where in each case I'm ... know who I listed as my friends, in which case I'll only check to see who I ...
    (microsoft.public.excel.programming)
  • Re: vb.net combine two byte arrays
    ... Ok I just dumped a test array to see what is the behavior you have. ... Source elements and then Destination elements rather than the other way ... >> the source array data/size etc. ... >> CompletedFile is the array to hold the two combined byte arrays and is ...
    (microsoft.public.dotnet.framework.aspnet)