Código
Option Explicit 'cSet by Slek, for Indetectables.net '31/5/2012 'Nota: Es un conjunto de Integer (puede ser modificado) ' It's an Integer's Set (can be modified) Dim Arr() As Integer 'Array of elements Dim s As Integer 'Number of elements included Private Sub Class_Initialize() 'Initialize with 0 elements s = 0 End Sub Public Sub add(ByVal n As Integer) 'Include n If Not contains(n) Then ReDim Preserve Arr(s) Arr(s) = n s = s + 1 End If End Sub Public Sub remove(ByVal n As Integer) 'Exclude n Dim i As Integer Dim b As Boolean For i = 0 To (s - 2) If Arr(i) = n Then b = True If b Then Arr(i) = Arr(i + 1) Next i s = s - 1 ReDim Preserve Arr(s - 1) End Sub Public Function size() As Integer 'Return number of elements size = s End Function Public Function contains(ByVal n As Integer) As Boolean 'Returns if n has already been included Dim i As Integer For i = 0 To (s - 1) If Arr(i) = n Then contains = True Exit Function End If Next i contains = False End Function Public Function toArray() As Integer() 'Return Array toArray = Arr End Function
Ejemplo de uso:
Código
Dim c As New cSet Dim a() As Integer Call c.add(1) MsgBox c.Contains(1) Call c.add(1) Call c.add(30) MsgBox c.size Call c.remove(1) a = c.toArray
Saludos!!