Consulting

Results 1 to 2 of 2

Thread: How to remove a member from a collection.

  1. #1
    VBAX Regular
    Joined
    Sep 2006
    Posts
    65
    Location

    How to remove a member from a collection.

    I have just created my first collection and I'm fairly new to these classes.
    I would like to remove a member from my collection, I've created the subroutine SRemove, which I want to remove a member, however I get the error: sub or function not defined.

    Here is the code:
    EDIT: copy pasted it wrong

    [vba]
    Sub test()
    Static x As New xts
    Dim i, j, k As Integer
    For i = 1 To 3
    MsgBox x.count((i))
    Next i

    Call SRemove(3, 1)
    For i = 1 To x.count(1)
    MsgBox x.Item((i), 1).y
    Next i
    End Sub

    'A Class Module named xt
    Private my As Integer
    Property Get y() As Integer
    y = my
    End Property
    Property Let y(newvalue As Integer)
    my = newvalue
    End Property
    End Sub

    'A Class Module named xts
    Option Base 1
    Private mxts(3) As Collection
    Private Sub Class_Initialize()
    Dim i, j, k As Integer
    Dim objxt As xt
    For j = 1 To 3
    Set mxts(j) = New Collection
    For i = 1 To 5
    Set objxt = New xt
    If Cells(i, j) > 0 Then
    objxt.y = Cells(i, j)
    mxts(j).Add objxt
    End If
    Next i
    Next j
    End Sub
    Public Function Item(index As Integer, j As Integer) As xt
    Set Item = mxts(j).Item(index)
    End Function
    Public Property Get count(j As Integer) As Long
    count = mxts(j).count
    End Property

    Public Sub SRemove(index, j As Integer)
    Set mxts(j) = New Collection
    mxts(j).remove index
    End Sub
    [/vba]

    Can some please tell me what I'm doing wrong .

    Please.

    /troelsi
    Last edited by troelsi; 03-02-2008 at 01:05 PM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That code doesn't compile, you have code after the end sub.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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