home *** CD-ROM | disk | FTP | other *** search
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "Errors"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- ' Simple Errors Class Module
- ' Keeps Track of Errors for any System
-
- Option Explicit
- Option Compare Text
-
- Private Type tErrs ' Error Trap Structure.
-
- Number As Long ' Error Number.
- Source As String ' Source of Error.
- Description As String ' Description or Error.
- Action As String ' Action being carried out.
-
- End Type
-
- Public ErrCount As Integer ' External Error Counter
- Private ColErrs As New Collection ' Internal Error Collection.
- Private tErrs As tErrs ' Localise the Structure.
- Public Property Get Number() As Long ' Returns the current errors Number.
- If ColErrs.Count Then Number& = tErrs.Number
- End Property
- Public Property Get Description() As String ' Returns the current errors Description.
- If ColErrs.Count Then Description$ = tErrs.Description
- End Property
- Public Property Get Source() As String ' Returns the current errors Source.
- If ColErrs.Count Then Source$ = tErrs.Source
- End Property
- Public Property Get Action() As String ' Returns the current errors Action.
- If ColErrs.Count Then Action$ = tErrs.Action
- End Property
- Public Property Get Count() As Integer ' Returns the current error Count.
- Count% = ColErrs.Count
- End Property
-
- ' Returns an array for all errors since the last refresh.
-
- Public Function Errors() As Variant
-
- Dim vError() As Variant
- Dim vErr As Variant
- Dim x As Integer
- Dim y As Integer
-
- ReDim vError(0 To ColErrs.Count, 4) As Variant
-
- If ColErrs.Count > 0 Then ' Only if Errors Exist.
- For x% = 1 To UBound(vError)
- vErr = ColErrs(x%)
- If IsArray(vErr) Then
- vError(y%, 0) = vErr(0) ' Set the Error Number.
- vError(y%, 1) = vErr(1) ' Set the Error Description.
- vError(y%, 2) = vErr(2) ' Set the Error Source.
- vError(y%, 3) = vErr(3) ' Set the Error Action.
- y% = y% + 1
- End If
- Next x%
- If IsArray(vError) Then Errors = vError ' Set the Complete Return Value.
- End If
-
- End Function
-
- ' Adds a Member to the 'ColErrs' Collection
-
- Public Function Add(Num As Long, Desc As String, Optional Source, Optional Action) As Variant
-
- Dim vArray(4) As Variant
-
- On Error Resume Next
-
- tErrs.Number = Num&
- tErrs.Description = IIf(IsEmpty(Desc), "", Desc)
- tErrs.Source = IIf(IsMissing(Source) Or IsEmpty(Source) Or CStr(Source) <= "", "ImeXOle", Source)
- tErrs.Action = IIf(IsMissing(Action) Or IsEmpty(Action) Or CStr(Action) <= "", "?", Action)
-
- ' Log Errors to File if a Valid Log Filename has been set.
-
- If LogOpen Then
- LogFile "Error : " & Num& & " Desc : " & Desc & " Action : " & CStr(Action)
- End If
-
- vArray(0) = tErrs.Number
- vArray(1) = tErrs.Description
- vArray(2) = tErrs.Source
- vArray(3) = tErrs.Action
-
- Inc ErrCount% ' One more error.
-
- ColErrs.Add Item:=vArray(), Key:=Trim$(CStr(ErrCount%))
-
- Add = CVar(vArray) ' Return the Array.
-
- End Function
-
- ' Clears all Errors from the ColErrs Collection.
-
- Public Sub Refresh()
-
- On Error Resume Next
-
- RefreshAgain: Do While ColErrs.Count > 0
- ColErrs.Remove 1
- Loop
-
- If ColErrs.Count = 0 Then ErrCount% = 0 Else GoTo RefreshAgain
-
- End Sub
-