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. Arrays

Arrays

Scheduled Pinned Locked Moved Visual Basic
data-structureshelpquestion
5 Posts 2 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.
  • C Offline
    C Offline
    Cedrickdeorange
    wrote on last edited by
    #1

    I am have problems adding records to an array. I am using a structure and an arraylist Code Snippet Public Persons As New ArrayList Public Structure Person Public First As String Public Last As String Public Home As String Public Work As String Public Mobile As String End Structure and the next block is to add a record to the list Code Snippet Dim p As New Person p.First = txtFirst2.Text p.Last = txtLast2.Text p.Home = txtHome2.Text p.Work = txtWork2.Text p.Mobile = txtMobile2.Text Persons.Add(p) lstPhone.Items.Add(p.First + " " + p.Last) The above code works but the trouble i'm having now is I cannot append to the array or save it. Can anyone help? Thanks all :((

    Regards Zeldacat

    L 1 Reply Last reply
    0
    • C Cedrickdeorange

      I am have problems adding records to an array. I am using a structure and an arraylist Code Snippet Public Persons As New ArrayList Public Structure Person Public First As String Public Last As String Public Home As String Public Work As String Public Mobile As String End Structure and the next block is to add a record to the list Code Snippet Dim p As New Person p.First = txtFirst2.Text p.Last = txtLast2.Text p.Home = txtHome2.Text p.Work = txtWork2.Text p.Mobile = txtMobile2.Text Persons.Add(p) lstPhone.Items.Add(p.First + " " + p.Last) The above code works but the trouble i'm having now is I cannot append to the array or save it. Can anyone help? Thanks all :((

      Regards Zeldacat

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This code works just fine. I'm not sure what type of control lstPhone is, but this below code will work just fine. Question: Why are you using a Structure instead of a class? Question: Why are you using an ArrayList instead of a Generic List(Of Person)? This would provide a type safe collection.

      Public Structure Person
      Public First As String
      Public Last As String
      Public Home As String
      Public Work As String
      Public Mobile As String
      End Structure

      Public Class Class1

      Public Persons As New ArrayList

      Public Sub New()
      Dim p As New Person
      p.First = "hello"
      p.Last = "There"
      p.Home = "555-1212"
      p.Work = "411"
      p.Mobile = "900-555-1212"
      Persons.Add(p)

      ' this will work just fine
      'I'm assuming that lstPhone is a Combo Box or List Box?
      
      'lstPhone.Items.Add(p.First + " " + p.Last)
      

      End Sub

      End Class

      Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

      Just a grain of sand on the worlds beaches.

      C 1 Reply Last reply
      0
      • L Lost User

        This code works just fine. I'm not sure what type of control lstPhone is, but this below code will work just fine. Question: Why are you using a Structure instead of a class? Question: Why are you using an ArrayList instead of a Generic List(Of Person)? This would provide a type safe collection.

        Public Structure Person
        Public First As String
        Public Last As String
        Public Home As String
        Public Work As String
        Public Mobile As String
        End Structure

        Public Class Class1

        Public Persons As New ArrayList

        Public Sub New()
        Dim p As New Person
        p.First = "hello"
        p.Last = "There"
        p.Home = "555-1212"
        p.Work = "411"
        p.Mobile = "900-555-1212"
        Persons.Add(p)

        ' this will work just fine
        'I'm assuming that lstPhone is a Combo Box or List Box?
        
        'lstPhone.Items.Add(p.First + " " + p.Last)
        

        End Sub

        End Class

        Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

        Just a grain of sand on the worlds beaches.

        C Offline
        C Offline
        Cedrickdeorange
        wrote on last edited by
        #3

        Sorry Karl I made a bit of a boo boo here. I forgot to add the fact, i'm using a .csv file to append the new persons data to. I might get a thread going properly one day. :confused:

        Regards Zeldacat

        L 1 Reply Last reply
        0
        • C Cedrickdeorange

          Sorry Karl I made a bit of a boo boo here. I forgot to add the fact, i'm using a .csv file to append the new persons data to. I might get a thread going properly one day. :confused:

          Regards Zeldacat

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Cedrickdeorange wrote:

          I forgot to add the fact, i'm using a .csv file to append the new persons data to.

          How does this change anything? You can read your .csv file, record by record and still load a Generic Collection List(Of Person). Am I missing something?

          Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

          Just a grain of sand on the worlds beaches.

          C 1 Reply Last reply
          0
          • L Lost User

            Cedrickdeorange wrote:

            I forgot to add the fact, i'm using a .csv file to append the new persons data to.

            How does this change anything? You can read your .csv file, record by record and still load a Generic Collection List(Of Person). Am I missing something?

            Cheers, Karl My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

            Just a grain of sand on the worlds beaches.

            C Offline
            C Offline
            Cedrickdeorange
            wrote on last edited by
            #5

            :confused: No. I know where you're going with this now. I had another look at the first post again. I wasn't thinking that way at the time. As i said it all makes sense now. Thanks.

            Regards Zeldacat

            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