CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    A Collection of user define type

    How to write a user define type of Collection? The following code won't work.
    Type EmployeeRecord
    ID As Integer
    Name As String
    Address As String
    End Type

    Sub CreateRecord()
    Dim MyRecord As EmployeeRecord
    Dim MyCollection As Collection

    MyRecord.ID = 12003 ' Assign a value to an element.
    Set MyCollection = new Collection
    MyCollection.Add(MyRecord)
    End Sub



  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: A Collection of user define type

    Collections Work only on objects. So turn your employee type into a class and it will work.
    Some thing like this:
    Add a Class, and name it CEmployeeRecord
    in it put these members. Make them all Public

    public ID as Integer
    public Name as string
    public Address as string



    and biuld your collection like this:

    Sub CreateRecord()
    Dim MyRecord as CEmployeeRecord
    Dim MyCollection as Collection

    set MyRecord = new CEmployeeRecord
    MyRecord.ID = 12003 ' Assign a value to an element.
    set MyCollection = new Collection
    MyCollection.Add(MyRecord)
    set MyRecord = nothing
    End Sub





    RK

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

Featured