[AccessD] Log file - part 2

JWColby jwcolby at colbyconsulting.com
Sun Jan 7 21:32:26 CST 2007


Error handling is a complex subject, and one which is difficult to
generalize.  The framework can generate errors which are unrelated directly
to the application.  It can also generate errors that are directly related
to the application.  It can generate errors which are caused by activity up
in the application and just manifests inside the framework.  And of course
the application can generate errors which are never handled by the
framework.

One of the problem with raising errors and causing them to be handled
somewhere is that you can never be sure where they will be handled,
particularly if they are buried down in code.  A better solution would be to
send messages, and have an object that listens to those messages.  I want
framework errors to be directed to me, and perhaps to someone else (a super
user), but I want application errors to be handled mostly by the super
users, calling me only if they cannot figure out what to do.

I have a message class, the framework exposes these message channels similar
to how it exposes a log file.  Any object can talk over the message channel,
it is really a matter of "how".  The message channels can be public (a
public function can send the message) but the receipt of messages utilizes
sinking events, so each object that wants to RECEIVE messages has to
dimension the message class WITHEVENTS and then sink the message class'
events.  A message class, with a public function to SEND messages, but SUNK
in an error handler class would probably be the best solution to this kind
of problem.  Then any function could report an error just by calling a
public function and the message handler (really mostly a logger / emailer)
could sink the message events and handle them, perhaps by writing them to a
table or a file, or generating an email.  That would work for "unexpected"
errors which the code simply does not know how to handle, and needs to alert
someone that the error happened.

John W. Colby
Colby Consulting
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Robert
Sent: Sunday, January 07, 2007 2:02 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Log file - part 2

John,
 Have you thought about having your classes or "Objects" pass any errors to
the calling form or function, rather then generating the error message
direction from the class? 

Something like incorporating an "Error Object" within your classes
(Framework), letting the object raise the error, and the listeners response
to the error?  Maybe over kill...

Robert



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of JWColby
Sent: Saturday, January 06, 2007 3:47 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Log file - part 2

Nope.  I haven't done a runtime in ages. 


John W. Colby
Colby Consulting
www.ColbyConsulting.com

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of William Hindman
Sent: Saturday, January 06, 2007 2:28 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Log file - part 2

JC

.....have you tested the FSO to run in a runtime install?

William Hindman

----- Original Message -----
From: "JWColby" <jwcolby at colbyconsulting.com>
To: "'Access Developers discussion and problem solving'" 
<accessd at databaseadvisors.com>
Sent: Saturday, January 06, 2007 12:21 PM
Subject: [AccessD] Log file - part 2


> This is the class text described in part 1.
>
> The following is the log file class.  It is a work in progress, but 
> any additions you need, you can add.
>
> Option Compare Database
> Option Explicit
> '.
>
'.=========================================================================
> '.Copyright    : cColby Consulting 2000.  All rights reserved.
> '.E-mail       : jcolby at ColbyConsulting.com
>
'.=========================================================================
> ' DO NOT DELETE THE COMMENTS ABOVE.  All other comments in this module 
> ' may be deleted from production code, but lines above must remain.
>
'--------------------------------------------------------------------------
> '.Written By   : John W. Colby
> '.Date Created : 05/29/2002
> '.Rev. History :
> '.Comments     :
>
'.-------------------------------------------------------------------------
> '.
> ' ADDITIONAL NOTES:
> '
> ' BEHAVIORS:
> '
> '*+ Class constant declaration
> Private Const DebugPrint As Boolean = False Private Const 
> mcstrModuleName As String = "clsLogFile"
> '*- Class constant declaration
>
> '*+ Class variables declarations
> 'THE STRING INSTANCE NAME IS BUILT UP FROM THE MODULE NAME AND 'A 
> RANDOM INT Private mname As String
> '*- Class variables declarations
>
> '*+ custom constants declaration
> '*- custom constants declaration
>
> '*+ custom variables declarations
> Private mFSO As Scripting.FileSystemObject Private mTS As 
> Scripting.TextStream
>
> Private mstrFileName As String
> Private mstrFileExt As String
> Private mstrFilePath As String
> Private mstrFileSpec As String
> Private mstrDteFmt As String
> Private mstrDte As String
> Private mstrTimeFmt As String
> Private mstrTime As String
> '*- custom variables declarations
> '*+ Private Init/Terminate interface
> Private Sub Class_Initialize()
>    Randomize
>    mname = strModuleName & ":" & Random(999999, 0)  'Make a random 
> name for ourself
>    Set mFSO = New Scripting.FileSystemObject End Sub Private Sub
> Class_Terminate() On Error Resume Next
>    Term
>    Set mobjChildren = Nothing
>    Set mobjParent = Nothing
>    Set mFSO = Nothing
>    mTS.Close
>    Set mTS = Nothing
> End Sub
> '*- Private Init/Terminate interface
>
> '*+ Public Init/Terminate interface
> Public Function Init(ByRef robjParent As Object, _
>                        strFilePath As String, strFileName As String, 
> strFileExt As String, _
>                        Optional strDteFmt As String = "", Optional 
> strTimeFmt As String = "") As Boolean On Error GoTo Err_Init
>
>    mstrFilePath = strFilePath
>    mstrFileName = strFileName
>    mstrFileExt = strFileExt
>    mstrDteFmt = strDteFmt
>    mstrTimeFmt = strTimeFmt
>    '
>    'Now that we have stored the file spec pieces, create a file spec
>    mFmtFileSpec
>
> Exit_Init:
> Exit Function
> Err_Init:
>        MsgBox err.Description, , "Error in Function clsLWS.Init"
>        Resume Exit_Init
>    Resume 0    '.FOR TROUBLESHOOTING
> End Function
> 'CLEAN UP ALL OF THE CLASS POINTERS
> Public Sub Term()
>    On Error Resume Next
> End Sub
> '*- Public Init/Terminate interface
>
> 'get the name of this class / module
> Property Get strModuleName() As String
>    strModuleName = mcstrModuleName
> End Property
> 'get the pointer to this object's instance name Public Property Get
> name() As String
>    name = mname
> End Property
> '*+ Parent/Child links interface
> Property Get pFileName() As String
>    pFileName = mstrFileName
> End Property
> Property Let pFileName(strFileName As String)
>    mstrFileName = strFileName
> End Property
> Property Get pFileExt() As String
>    pFileExt = mstrFileExt
> End Property
> Property Let pFileExt(strFileExt As String)
>    mstrFileExt = strFileExt
> End Property
> Property Get pFilePath() As String
>    pFilePath = mstrFilePath
> End Property
> Property Let pFilePath(strFilePath As String)
>    mstrFilePath = strFilePath
> End Property
> Property Get pFileSpec() As String
>    pFileSpec = mstrFileSpec
> End Property
> Property Get pFSO() As Scripting.FileSystemObject
>    Set pFSO = mFSO
> End Property
> Property Get pTS() As Scripting.TextStream
>    Set pTS = mTS
> End Property
> '*- Parent/Child links interface
> '*+ Withevents interface
> '*- Withevents interface
> '*+ Private class functions
> '*- Private class functions
> '*+ Public class functions
> '
> 'This function creates the time string portion of the file spec at the 
> instant this function is called '
> Private Function mFmtTime() As String
> On Error GoTo Err_mFmtTime
>    If Len(mstrTimeFmt) Then
>        mstrTime = Format(Time(), mstrTimeFmt)
>    End If
>    mFmtTime = mstrTime
> Exit_mFmtTime:
> Exit Function
> Err_mFmtTime:
>        MsgBox err.Description, , "Error in Function clsLogFile.mFmtTime"
>        Resume Exit_mFmtTime
>    Resume 0    '.FOR TROUBLESHOOTING
> End Function
> '
> 'This function creates the date string portion of the file spec at the 
> instant this function is called '
> Private Function mFmtDte() As String
> On Error GoTo Err_mFmtDte
>    If Len(mstrDteFmt) Then
>        mstrDte = Format(date, mstrDteFmt)
>    End If
>    mFmtDte = mstrDte
> Exit_mFmtDte:
> Exit Function
> Err_mFmtDte:
>        MsgBox err.Description, , "Error in Function clsLogFile.mFmtDte"
>        Resume Exit_mFmtDte
>    Resume 0    '.FOR TROUBLESHOOTING
> End Function
> '
> 'This function creates the file spec string '
> Function mFmtFileSpec() As String
>    mstrFileSpec = mstrFilePath & mstrFileName
>    If Len(mstrDteFmt) Then
>        mstrFileSpec = mstrFileSpec & "-" & mFmtDte
>    End If
>    If Len(mstrTimeFmt) Then
>        mstrFileSpec = mstrFileSpec & "-" & mFmtTime
>    End If
>   mstrFileSpec = mstrFileSpec & "." & mstrFileExt End Function Public 
> Function mFSGetWrite()
>    Set mTS = mFSO.CreateTextFile(mstrFileSpec) End Function Public 
> Function mFSGetRead()
>    Set mTS = mFSO.OpenTextFile(mstrFileSpec) End Function Public 
> Function mFSClose()
>    mTS.Close
> End Function
> '*- Public class functions
>
> John W. Colby
> Colby Consulting
> www.ColbyConsulting.com
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list