CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2009
    Posts
    31

    Can't add class item to Collection..

    I've defined a collection in my form:
    Code:
    private toDelete as new Collection
    In my delete button I have this:
    Code:
    Private sub cmdDelete_Click()
    Dim TM as new TestMeth
    TM.X="foo"
    TM.Y="bar"
    
    toDelete.Add(TM)
    end sub
    TestMeth is a Class Module that has a bunch of Get/Let Properties

    I get this error when trying to add it to the collection:

    Run-time error '438'
    Object doesn't support this property or method

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Can't add class item to Collection..

    It seems your TestMeth Class does not define the properties X or Y.
    Everything else is syntactically correct. Please examine the code of the class module if there are proper definitions of property routines (Let and Get) for X and Y
    Code:
    Public Property Let X (A as string)
    End Property
    If in doubt you ought to post the code of this class, so as we can take a look.

  3. #3
    Join Date
    Jun 2009
    Posts
    31

    Re: Can't add class item to Collection..

    TestMeth Class
    Code:
    Private m_sX As String
    Private m_sY As String
    
    Public Property Get X() As String
        Line = m_sX
    End Property
    
    Public Property Let X(ByVal Value As String)
        m_sX = Value
    End Property
    
    Public Property Get Y() As String
        Method = m_sY
    End Property
    
    Public Property Let Y(ByVal Value As String)
        m_sY = Value
    End Property

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Can't add class item to Collection..

    Use the add method without the brackets
    Code:
    toDelete.Add TM

  5. #5
    Join Date
    Jun 2009
    Posts
    31

    Re: Can't add class item to Collection..

    Quote Originally Posted by Shuja Ali View Post
    Use the add method without the brackets
    Code:
    toDelete.Add TM
    Thanks worked like a charm

  6. #6
    Join Date
    Sep 2006
    Posts
    635

    Re: Can't add class item to Collection..

    or use call statement too.
    Code:
    call toDelete.Add(TM)

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Can't add class item to Collection..

    Or (that's why I did not spot this) put a blank in.
    Strangely enough toDelete.Add (TM) works, too.

Tags for this Thread

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