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. Visual Basic
  4. Copying one array element to another array

Copying one array element to another array

Scheduled Pinned Locked Moved Visual Basic
data-structures
3 Posts 3 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.
  • R Offline
    R Offline
    Razanust
    wrote on last edited by
    #1

    I have written a code to read a text box character by character and copy the characters into another array. As soon as the space character occurs the process should stop. the Program is giving argument null exception at runtime. Any solutions. Here is the code. Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click Dim objreader As New System.IO.StreamReader(file_name.Text) TextBox1.Text = objreader.ReadLine TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf Dim myArray() As Char Dim myArray2() As Char myArray = Me.TextBox1.Text.ToCharArray For i As Integer = 1 To 70 If myArray(i) <> " " Then Else Array.Copy(myArray, myArray2, i) End If Next End Sub

    L D 2 Replies Last reply
    0
    • R Razanust

      I have written a code to read a text box character by character and copy the characters into another array. As soon as the space character occurs the process should stop. the Program is giving argument null exception at runtime. Any solutions. Here is the code. Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click Dim objreader As New System.IO.StreamReader(file_name.Text) TextBox1.Text = objreader.ReadLine TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf Dim myArray() As Char Dim myArray2() As Char myArray = Me.TextBox1.Text.ToCharArray For i As Integer = 1 To 70 If myArray(i) <> " " Then Else Array.Copy(myArray, myArray2, i) End If Next End Sub

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      ArgumentNullException means one of the arguments is null ("Nothing" in your lingo). Dim myArray2() As Char is not allocating any memory, it only tells the compiler myArray2 is going to refer to some char array, however you (or something you call) needs to pay for the memory (as Me.TextBox1.Text.ToCharArray did for the other array reference). Try the New keyword. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      1 Reply Last reply
      0
      • R Razanust

        I have written a code to read a text box character by character and copy the characters into another array. As soon as the space character occurs the process should stop. the Program is giving argument null exception at runtime. Any solutions. Here is the code. Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click Dim objreader As New System.IO.StreamReader(file_name.Text) TextBox1.Text = objreader.ReadLine TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf Dim myArray() As Char Dim myArray2() As Char myArray = Me.TextBox1.Text.ToCharArray For i As Integer = 1 To 70 If myArray(i) <> " " Then Else Array.Copy(myArray, myArray2, i) End If Next End Sub

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        See the code below, this example using a textbox and a button for the example. The code below is in the button click event;

        Dim out As List(Of Char) = New List(Of Char)

        If Not IsNothing(TextBox1.Text) Then
        For Each item As Char In TextBox1.Text.ToCharArray
        If item <> Chr(32) Then
        out.Add(item)
        Debug.WriteLine(item.ToString)
        Else
        Debug.WriteLine("Space found......stopping.")
        Exit For
        End If

        Next
        

        End If

        If out.Count > 0 Then
        Debug.WriteLine("Out Array Contains: " + out.Count.ToString + " items.")

        Dim outString As New System.Text.StringBuilder
        outString.Append("Out contains: ")
        For Each item As Char In out
            outString.Append(item.ToString)
        Next
        Debug.WriteLine(outString.ToString)
        

        Else
        Debug.WriteLine("No items in output array")
        End If

        Dave Find Me On: Web|Facebook|Twitter|LinkedIn


        Folding Stats: Team CodeProject

        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