VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CDocs"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
'  This collection class manages the creation, removal, and group saving of all CDoc objects.
Option Explicit

Private m_colDocs As Collection
'  This property procedure returns the number of doc objects in collection
Public Property Get Count() As Long


    ' return the number of doc objects in collection
    Count = m_colDocs.Count
    
    
End Property
'  This procedure adds a new CDoc object to the collection and return a reference
'       to the newly added CDoc object.
Public Function MakeNew() As CDoc


    Static ilDocCounter As Long
    Dim TempDoc As New CDoc
    
    ' set reference to form interface object
    Set TempDoc.Face = New frmDocFace
    With TempDoc
        ' make this object the editor object of the form interface object
        Set .Face.ParentObject = TempDoc
        ' setup text box to match properties of program (the editor object)
        With .Face!txtDoc
            .BackColor = Editor.BackColor
            .ForeColor = Editor.ForeColor
            .FontBold = Editor.FontBold
            .FontItalic = Editor.FontItalic
            .FontName = Editor.FontName
            .FontSize = Editor.FontSize
            .FontStrikethru = Editor.FontStrikethru
            .FontUnderline = Editor.FontUnderline
        End With ' .Face!txtDoc
        ' if this was an actual program it would be necessary to make sure that this variable never goes
        '   above 2,147,483,647.  Then again, who would open that many documents in 1 running of the program?
        ilDocCounter = ilDocCounter + 1
        .ID = ilDocCounter
     
        .Caption = "Document" & CStr(ilDocCounter)
        With .Face
            .Form_Resize
            .Visible = True
        End With ' .Face
    End With ' TempDoc
    
    ' add this new document the collection of documents
    m_colDocs.Add Item:=TempDoc, Key:=CStr(ilDocCounter)
    
    ' return reference to this new CDoc object
    Set MakeNew = TempDoc
    

End Function
'  This procedure removes the specified CDoc object from the collection and sets it to nothing
Public Sub Remove(YourDoc As CDoc)

    
    On Error Resume Next ' just in case the document is not found
    
    Dim sKey As String
    
    sKey = CStr(YourDoc.ID)
    m_colDocs.Remove sKey
    ' clear reference to form interface object
    Set YourDoc.Face = Nothing
    ' clear object
    Set YourDoc = Nothing
    

End Sub
Public Sub SaveAll()


    ' call the save method for all doc objects which have data to be saved
    Dim TempDoc As CDoc
    For Each TempDoc In m_colDocs
        ' if this document has a file name then call its Save method
        If Trim$(TempDoc.FileName) <> "" Then
            TempDoc.Save
        Else
            ' do a save as by calling the 'save as' method of the editor object
            Call Editor.SaveFileAs(TempDoc)
        End If
    Next TempDoc


End Sub
Private Sub Class_Initialize()


    ' initialize private data
    Set m_colDocs = New Collection
    
    
End Sub
