VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsGroup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'-----------------------------------------------------
' MirageBot Group Class
' Written by Christopher Nevin (lancergli@gmail.com)
'-----------------------------------------------------

Option Explicit
Option Compare Text

Private GroupMembers() As String
Public Name As String
Public Color As Long

Public Function Members() As String()
    Members = GroupMembers
End Function

Public Sub SaveGroup()
On Error GoTo hErr
    Open AppData & "Data\Preferences\Groups\" & Name & ".txt" For Append As #1: Close #1
    Open AppData & "Data\Preferences\Groups\" & Name & ".txt" For Output As #1
        Print #1, "Color=" & Color
        Dim I As Integer, Count As Long
        Count = UBound(GroupMembers)
        For I = 0 To Count
            Print #1, GroupMembers(I)
        Next I
    Close #1
    Exit Sub
hErr:
    Close #1
    ErrorHandler Err.Number, Err.Description, Erl, "Group", "SaveGroup"
End Sub

Public Function IsInGroup(ByVal User As String) As Boolean
On Error GoTo hErr
    Dim I As Integer, Count As Long
    User = User
    Count = UBound(GroupMembers)
    For I = 0 To Count
        If GroupMembers(I) = User Then
            IsInGroup = True
            Exit Function
        End If
    Next I
    Exit Function
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Group", "IsInGroup"
End Function

Public Function MemberCount() As Integer
On Error GoTo hErr
    MemberCount = UBound(GroupMembers)
hErr:
End Function

Public Sub Clear()
    ReDim GroupMembers(0)
End Sub

Public Function Remove(ByVal User As String) As Boolean
On Error GoTo hErr
    Dim I As Integer, N As Integer, Count As Long
    User = User
    Count = UBound(GroupMembers)
    For I = 0 To Count
        If GroupMembers(I) = User Then
            If UBound(GroupMembers) > 0 Then
                Dim Count2 As Long
                Count2 = UBound(GroupMembers) - 1
                For N = I To Count2
                    GroupMembers(N) = GroupMembers(N + 1)
                Next N
                ReDim Preserve GroupMembers(Count2)
            Else
                Clear
            End If
            Remove = True
            Exit Function
        End If
    Next I
    Exit Function
hErr:
    Close #1
    ErrorHandler Err.Number, Err.Description, Erl, "Group", "Remove"
End Function

Public Sub Add(User As String)
On Error GoTo hErr
    If (LenB(GroupMembers(0)) = 0) Then
        GroupMembers(0) = User
    Else
        ReDim Preserve GroupMembers(UBound(GroupMembers) + 1)
        GroupMembers(UBound(GroupMembers)) = User
    End If
    Exit Sub
hErr:
    Close #1
    ErrorHandler Err.Number, Err.Description, Erl, "Group", "Add"
End Sub
