Results 1 to 6 of 6

Thread: Arraylist of structures

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Madras
    Posts
    13

    Question Arraylist of structures

    How do I use an arraylist to access,modify,add to and delete the items of a structure? say I have this structure:

    structure autos
    dim make as string
    dim model as string
    end structure

    On my form I have a listbox and 2 textboxes!

    lstcars & txtmodel and txtmake. How do I get the txtmodel and txtmake to output the model and make with a arraylist? modify the make, delete the make also?


    John

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    An Arraylist is a collection object. You can add and delete from the collection dynamically. If you ever used VB 6, you would have to use an array and then redim if you wanted the size to grow.

    With the ArrayList its all dynamic. So I dont think thats what you are looking for. All the ArrayList does is stores you collection of objects.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Madras
    Posts
    13
    I would like to learn these things I just can't seem find a good example on the web. If you can think of one thank you .

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If you plan on using DataBinding then I'd advise switching that structure to a class and use properties instead of fields because databinding doesn't like fields.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Madras
    Posts
    13
    [SIZE=3]Structure trans[Structure trans
    Dim number As Integer
    Dim type As String
    Dim amount As Single
    End Structure
    Dim transaction As trans
    Dim fv As StreamReader = File.OpenText("trans.txt")


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim transarray As New ArrayList
    Dim trans_array As New ArrayList
    Dim icounter As Int16
    transarray = get_transactions(trans_array)
    output_transactions(transarray)



    End Sub
    Function get_transactions(ByRef array As ArrayList) As ArrayList
    Dim trans_counter As Integer
    Dim trans_read() As String
    Do
    trans_read = fv.ReadLine.Split(","c)
    transaction.amount = trans_read(0)
    transaction.type = Convert.ToString(trans_read(1))
    transaction.number = trans_read(2)
    array.Add(transaction)
    trans_counter = +1
    Loop Until fv.Peek = -1
    Return array

    End Function
    Private Sub output_transactions(ByVal array As ArrayList)
    Dim transactions As trans
    Dim trans_counter As Integer
    For Each transactions In array
    lstaccounts.Items.Add(transactions.number)

    Next
    End Sub

    Private Sub lstaccounts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstaccounts.SelectedIndexChanged
    Dim trans_array As ArrayList
    txt_type.Text = transaction.type
    txt_amount.Text = transaction.amount

    End Sub/SIZE]









    I am trying to get the transaction type and amount to be outputted to the textboxes when the user click on an account number in the list box . Where did I go wrong
    Attached Files Attached Files

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Madras
    Posts
    13
    Originally posted by RBCC
    [SIZE=3]Structure trans[Structure trans
    Dim number As Integer
    Dim type As String
    Dim amount As Single
    End Structure
    Dim transaction As trans
    Dim fv As StreamReader = File.OpenText("trans.txt")


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim transarray As New ArrayList
    Dim trans_array As New ArrayList
    Dim icounter As Int16
    transarray = get_transactions(trans_array)
    output_transactions(transarray)



    End Sub
    Function get_transactions(ByRef array As ArrayList) As ArrayList
    Dim trans_counter As Integer
    Dim trans_read() As String
    Do
    trans_read = fv.ReadLine.Split(","c)
    transaction.amount = trans_read(0)
    transaction.type = Convert.ToString(trans_read(1))
    transaction.number = trans_read(2)
    array.Add(transaction)
    trans_counter = +1
    Loop Until fv.Peek = -1
    Return array

    End Function
    Private Sub output_transactions(ByVal array As ArrayList)
    Dim transactions As trans
    Dim trans_counter As Integer
    For Each transactions In array
    lstaccounts.Items.Add(transactions.number)

    Next
    End Sub

    Private Sub lstaccounts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstaccounts.SelectedIndexChanged
    Dim trans_array As ArrayList
    txt_type.Text = transaction.type
    txt_amount.Text = transaction.amount

    End Sub/SIZE]









    I am trying to get the transaction type and amount to be outputted to the textboxes when the user click on an account number in the list box . Where did I go wrong

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width