PDA

View Full Version : How to remove a member from a collection.



troelsi
03-02-2008, 12:30 PM
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


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


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

Please.

/troelsi

Bob Phillips
03-02-2008, 12:34 PM
That code doesn't compile, you have code after the end sub.