Error Persistence Class

Author Message
ebgreen

  • Total Posts : 8227
  • Scores: 98
  • Reward points : 0
  • Joined: 7/12/2005
  • Status: online
Error Persistence Class Friday, March 09, 2007 3:55 AM (permalink)
0
I had written a class similar to this in the past and now I can't find it so I just re-wrote it real quick because someone had requested it. Basically it allows you to keep a running persistent list of error that you won't lose by performing an Err.Clear. Here is the code and I think it is pretty self explanatory, but I can add comments if others don't agree.
 
Option Explicit
 Dim oPE : Set oPE = New PersistentErrors
 Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
 Dim a
 Dim oErr
 Dim strKey
 On Error Resume Next
 a = 10/0
 oPE.AddError Err, "Division by zero test"
 Err.Clear
 On Error Resume Next
 oFSO.OpenTextFile("C:\foo\bar.txt")
 oPE.AddError Err, "Missing file test"
 Err.Clear
 For Each oErr In oPE.GetErrors()
  WScript.Echo "ERROR:"
  For Each strKey In oErr.Keys()
   WScript.Echo vbTab & strKey & " = " & oErr(strKey)
  Next
  WScript.Echo ""
 Next 
 
 Class PersistentErrors
  Private arrErrors()
  Private nErrorCount
  Sub Class_Initialize()
   nErrorCount = 0
  End Sub
  
  Public Property Get ErrorCount
   ErrorCount = nErrorCount
  End Property
  
  Public Sub AddError(oError, strComment)
   Dim dicTemp
   Set dicTemp = CreateObject("Scripting.Dictionary")
   dicTemp.Add "Number", oError.Number
   dicTemp.Add "Description", oError.Description
   dicTemp.Add "HelpContext", oError.HelpContext
   dicTemp.Add "HelpFile", oError.HelpFile
   dicTemp.Add "Source", oError.Source
   dicTemp.Add "Comment", strComment
   dicTemp.Add "TimeStamp", Now()
   ReDim Preserve arrErrors(nErrorCount)
   Set arrErrors(nErrorCount) = dicTemp
   nErrorCount = UBound(arrErrors) + 1 
  End Sub
  
  Public Function GetErrors()
   GetErrors = arrErrors
  End Function
  
 End Class

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9