Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. VB.NET Array.Copy Question

VB.NET Array.Copy Question

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpdata-structuresdiscussion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eric Whitmore
    wrote on last edited by
    #1

    Friends, I am trying to merge to byte arrays and can't seem to get my code to work. Code below. Can i get some thoughts on what might be happening? I have verified that the arrays DO have data in them(aka length > 0).

    Dim pdfBytesSyllabus As Byte() = pdf.GetPdfBytesFromHtmlStream(streamSyllabus, System.Text.Encoding.ASCII)
    Dim pdfBytesCenter As Byte() = pdf.GetPdfBytesFromHtmlStream(streamCenter, System.Text.Encoding.ASCII)
    Array.Copy(pdfBytesCenter, 0, pdfBytesSyllabus, pdfBytesSyllabus.Length, pdfBytesCenter.Length)

    Eric

    A W P 3 Replies Last reply
    0
    • E Eric Whitmore

      Friends, I am trying to merge to byte arrays and can't seem to get my code to work. Code below. Can i get some thoughts on what might be happening? I have verified that the arrays DO have data in them(aka length > 0).

      Dim pdfBytesSyllabus As Byte() = pdf.GetPdfBytesFromHtmlStream(streamSyllabus, System.Text.Encoding.ASCII)
      Dim pdfBytesCenter As Byte() = pdf.GetPdfBytesFromHtmlStream(streamCenter, System.Text.Encoding.ASCII)
      Array.Copy(pdfBytesCenter, 0, pdfBytesSyllabus, pdfBytesSyllabus.Length, pdfBytesCenter.Length)

      Eric

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Array.Copy won't work as it does not resize the destination array (pdfBytesSyllabus) to hold the additional data from pdfBytesCenter. The steps required are 1) Create a new array of sufficient length to hold both arrays 2) Copy pdfBytesSyllabus to the new array at index 0 3) Copy pdfBytesCenter to the new array at index pdfBytesSyllabus.Length Much the same thing could be done with a generic List Of Byte, which is really just an implementation of a resizable array with a lot of useful methods added.

      1 Reply Last reply
      0
      • E Eric Whitmore

        Friends, I am trying to merge to byte arrays and can't seem to get my code to work. Code below. Can i get some thoughts on what might be happening? I have verified that the arrays DO have data in them(aka length > 0).

        Dim pdfBytesSyllabus As Byte() = pdf.GetPdfBytesFromHtmlStream(streamSyllabus, System.Text.Encoding.ASCII)
        Dim pdfBytesCenter As Byte() = pdf.GetPdfBytesFromHtmlStream(streamCenter, System.Text.Encoding.ASCII)
        Array.Copy(pdfBytesCenter, 0, pdfBytesSyllabus, pdfBytesSyllabus.Length, pdfBytesCenter.Length)

        Eric

        W Offline
        W Offline
        wajeetalohana
        wrote on last edited by
        #3

        Hi Eric Whitmore Might possible u r making mistake in defining the number of items to be copied. Kindly review the the following link. http://msdn.microsoft.com/en-us/library/y5s0whfd.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]

        D 1 Reply Last reply
        0
        • W wajeetalohana

          Hi Eric Whitmore Might possible u r making mistake in defining the number of items to be copied. Kindly review the the following link. http://msdn.microsoft.com/en-us/library/y5s0whfd.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Uhhh...no. Alan nailed the problem exactly. You're just guessing at it.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          1 Reply Last reply
          0
          • E Eric Whitmore

            Friends, I am trying to merge to byte arrays and can't seem to get my code to work. Code below. Can i get some thoughts on what might be happening? I have verified that the arrays DO have data in them(aka length > 0).

            Dim pdfBytesSyllabus As Byte() = pdf.GetPdfBytesFromHtmlStream(streamSyllabus, System.Text.Encoding.ASCII)
            Dim pdfBytesCenter As Byte() = pdf.GetPdfBytesFromHtmlStream(streamCenter, System.Text.Encoding.ASCII)
            Array.Copy(pdfBytesCenter, 0, pdfBytesSyllabus, pdfBytesSyllabus.Length, pdfBytesCenter.Length)

            Eric

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            As Alan has said, the problem is to do with the fact that the array isn't big enough to contain this. A simple way to fix this is to create a generic list of bytes and add the data into it. You can easily get an array out of this like this:

            Dim pdfData As New List(Of [Byte])(pdfBytesSyllabus.Length + pdfBytesCenter.Length)
            pdfData.AddRange(pdfBytesCenter)
            pdfData.AddRange(pdfBytesSyllabus)
            ' To get an array, just use
            Dim cumulativePdfData As Byte() = pdfData.ToArray()

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            E 1 Reply Last reply
            0
            • P Pete OHanlon

              As Alan has said, the problem is to do with the fact that the array isn't big enough to contain this. A simple way to fix this is to create a generic list of bytes and add the data into it. You can easily get an array out of this like this:

              Dim pdfData As New List(Of [Byte])(pdfBytesSyllabus.Length + pdfBytesCenter.Length)
              pdfData.AddRange(pdfBytesCenter)
              pdfData.AddRange(pdfBytesSyllabus)
              ' To get an array, just use
              Dim cumulativePdfData As Byte() = pdfData.ToArray()

              I was brought up to respect my elders. I don't respect many people nowadays.
              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              E Offline
              E Offline
              Eric Whitmore
              wrote on last edited by
              #6

              Thanks Alan/Pete, Code worked great!

              Eric

              P 1 Reply Last reply
              0
              • E Eric Whitmore

                Thanks Alan/Pete, Code worked great!

                Eric

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                I'm glad I could help.

                I was brought up to respect my elders. I don't respect many people nowadays.
                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups