Results 1 to 3 of 3

Thread: Class and collections

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Class and collections

    VB Code:
    1. Class Account
    2.         Public Name As String, Number As String
    3.         Sub New(ByVal name As String, ByVal num As String)
    4.             Me.Name = name
    5.             Me.Number = num
    6.         End Sub
    7.     End Class
    8.  
    9.     Class AccountListCollection
    10.         Inherits CollectionBase
    11.         Sub Add(ByVal acct As Account)
    12.             Me.List.Add(acct)
    13.         End Sub
    14.         Sub Remove(ByVal acct As Account)
    15.             Me.List.Remove(acct)
    16.         End Sub
    17.         Default Property item(ByVal index As Integer) As Account
    18.             Get
    19.                 Return DirectCast(Me.List.Item(index), Account)
    20.             End Get
    21.             Set(ByVal Value As Account)
    22.                 Me.List.Item(index) = Value
    23.             End Set
    24.         End Property
    25.     End Class
    26.  
    27.     Private Sub AddAccountbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddAccountbtn.Click
    28.         Dim name, number As String
    29.         Dim newAccount As Account
    30.         With newAccount
    31.             .Name = InputBox("Account Name?")
    32.             .Number = InputBox("Number?")
    33.         End With
    34.     End Sub
    35. End Class
    I am trying to add a new account to the list, but don't even know if I am doing it right. The doesn't work anyway.

    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Class and collections

    VB Code:
    1. Private Sub AddAccountbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddAccountbtn.Click
    2.    Dim name, number As String
    3.  
    4.    Dim newAccount As New Account(InputBox("Account Name?"), InputBox("Number?"))
    5.  
    6.    Dim newAccountListCollection as new AccountListCollection
    7.  
    8.    newAccountListCollection.Add(newAccount)
    9. End Sub

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Class and collections

    thanks
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

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