473,725 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error Handler best practices

I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description &
vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible to
get this...)

How about offloading this to a module so I don't have to type it out every
time:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...
Nov 12 '05 #1
13 6607
RE/
I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description &
vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible to
get this...)

How about offloading this to a module so I don't have to type it out every
time:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...


Every routine I write is within the skeleton below.

"DebugStackPush ()", "DebugStackPop( )", and "BugAlert() " are all in
a module I call "basBugAler t".

The Push/Pop routines push the routine's name into an array/pop it out.

"BugAlert" refers to the array to get a trace of where we've been
just before the error popped. It then displays a little error screen to
the user and logs the error and the trace in a .TXT file.

The module is at the end of this note. If somebody can make it a little
better, I'd appreciate a copy of the improved code.

If you're trying to compile it and the line breaks are making you crazy, post
a reply and I'll email the .bas file to you.

-----------------------------------------------
Whatever()
DebugStackPush mModulename & ": Whatever"
On Error GoTo Whatever_err

' PURPOSE: To do whatever
' ACCEPTS:
' RETURNS:
'
' NOTES: 1).....
(code goes here...)

Whatever_xit:
DebugStackPop
On Error Resume Next
(release pointers, close recordsets)
Exit Sub

Whatever_err:
BugAlert True, ""
(optionally case out on Err if some errors are acceptable)
Resume Whatever_xit
----------------------------------------------
Option Compare Database 'Use database order for string comparisons
Option Explicit

' This module contains the routines used to trap/log errors and
' show the "bugAlert" screen.

' REQUIRES: 1) A table named "---------- Program Changes ----------" in the app
'
' 2) A global constant:
' Global Const gIniGroupName = "TretsParms "
'
' 3) Two forms:
' frmBugAlertConc ise
' frmBugAlertVerb ose
'
' NOTES: 1) To avoid loops, most of these routines should be using their own
own error trapping,
' which would be limited to just showing message boxes - as opposed
to potentially-recursive
' calls to debugStackPush( ) and debugStackPop()

Const mModuleName = "basBugAler t"

Global Const gStackLimit = 50

Const debugStackTotal Size = 52
Global gDebugStack(deb ugStackTotalSiz e)

Global gStackPointer As Integer

Global gErrorMessage As String 'For any calling routine
that wants to trap the error message before bugAlert munches on it.
Global gErrorLocation As String 'Ditto above, but contains
name of routine

Private Declare Function GetComputerName _bal Lib "kernel32" Alias
"GetComputerNam eA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName_bal Lib "advapi32.d ll" Alias "GetUserNam eA"
(ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetPrivateProfi leString Lib "kernel32" Alias
"GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String, ByVal lpKeyName
As Any, ByVal lpDefault As String, ByVal lpReturnedStrin g As String, ByVal nSize
As Long, ByVal lpFileName As String) As Long
Sub bugAlert(ByVal theDisplaySwitc h As Integer, ByVal theSupplemental Message As
String)

' PURPOSE: To log an error and, maybe, show an error screen to the user
' ACCEPTS: - A boolean telling whether-or-not to show a screen to the user
' - Supplemental text to be added to the log entry and shown on the
screen
' USES: - An optional .INI file parm called "myErrorPat h", which tells where
to write the error
' - An optional .INI file parm called "VerboseErrorDi splay" that tells
us if we want
' to show frmBugAlertVerb ose
'
' NOTES: 1) We are in error mode: anything could be happening.
' Therefore error trapping is limited to a messagebox.
' 2) We assume that the calling routine, after invoking this, will
gracefully proceed
' to it's "Exit" coding and pop the debug stack on the way out.
' 3) Note that out "On Error" statement isn't until *After* we've
captured error info.
' 4) Setting the display switch to False and suppling a supplemental
message allows the programmer
' to record things in the error log which did not result from
errors in the technical sense.
' e.g. bugAlert, False, "This sentence gets written to the error
log"
' 5) If there is no path specified in the .INI file, we write to the
root of C:

1001 Dim myErrorLine As Long
Dim myErrorNumber As Long
Dim myErrorMessage As String

1002 myErrorLine = Erl 'Capture relevant info ASAP
1003 myErrorNumber = Err
1004 myErrorMessage = Error$
1005 gErrorMessage = Error$
1006 gErrorLocation = gDebugStack(gSt ackPointer)

1007 On Error GoTo bugAlert_err
1008 DoCmd.Echo True 'In case it was turned off elsewhere

Dim v As Variant
Dim X As Integer
Dim myMessage As String
Dim myTimeStamp As String
Dim i As Integer
Dim L As Long
Dim myErrorPath As String
Dim myHeaderLine As String
Dim myAppVersion As String
Dim myVerboseSw As Boolean

Dim ParmValue As String

Const cannotDoAtThisT ime = 2486

Dim skipLine As String

1010 skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & " "

1011 DoCmd.SetWarnin gs True

1020 ParmValue = String(255, 0)
1021 L = GetPrivateProfi leString(gIniGr oupName, "ErrorLogPa th", "{NotFound} ",
ParmValue, 255, SysCmd(acSysCmd IniFile))
1022 If L And Left(ParmValue, 10) <> "{NotFound} " Then
1023 myErrorPath = Left(ParmValue, L)
1024 Else
1025 myErrorPath = CurrentDb().Nam e
1026 If Right(myErrorPa th, 4) = ".mdb" Then
1027 myErrorPath = Left(myErrorPat h, Len(myErrorPath ) - 4)
1028 End If
1029 myErrorPath = myErrorPath & ".Errors.tx t"
1030 End If

1040 ParmValue = String(255, 0)
1041 L = GetPrivateProfi leString(gIniGr oupName, "VerboseErrorDi splay",
"{NotFound} ", ParmValue, 255, SysCmd(acSysCmd IniFile))
1042 If L And Left(ParmValue, 10) <> "{NotFound} " Then
1043 If (Left(ParmValue , L) = "True") Or (Left(ParmValue , L) = "Yes") Then
1044 myVerboseSw = True
1045 End If
1046 End If

1049 myVerboseSw = True 'FORCE VERBOSE ERROR DISPLAY

1050 X = FreeFile
1051 Open myErrorPath For Append As X

1060 Print #X,
"-----------------------------------------------------------------"

1070 myAppVersion = currentVersionG et_bal
1071 myHeaderLine = VBA.Format$(Now , "mm/dd/yy hh:nn:ss") & myAppVersion & "
Userid: " & windozeIdGet_ba l() & " on " & computerNameGet _bal()

1080 Print #X, myHeaderLine

1090 If theDisplaySwitc h = False Then
1091 Print #X, "(ERROR SCREEN SUPPRESSED)"
1092 End If

1100 Print #X, " Proc: " & gDebugStack(gSt ackPointer)

1101 If myErrorNumber <> 0 Then
1102 If myErrorLine > 0 Then
1103 Print #X, String(9, " ") & "Line " & VBA.Format$(myE rrorLine,
"000000") & " " & VBA.Format$(myE rrorNumber, "0000") & ": " & myErrorMessage
1104 Else
1105 Print #X, String(13, " ") & VBA.Format$(myE rrorNumber, "0000") & ": "
& myErrorMessage
1109 End If
1110 Else
1111 If myErrorLine > 0 Then
1112 Print #X, String(9, " ") & "Line " & VBA.Format$(myE rrorLine,
"000000") & ": "
1113 Else
1114 Print #X, String(13, " ")
1115 End If
1119 End If

1120 If theSupplemental Message <> "" Then
1121 Print #X, Space$(19) & theSupplemental Message
1122 End If

1130 Print #X, ""

1140 If gStackPointer > 1 Then
1141 For i = 0 To gStackLimit
1142 If gDebugStack(i) <> "" Then
1143 If i = gStackPointer Then
1144 Print #X, Space$(9) & " " & Format(i, "00") & ">>" &
gDebugStack(i)
1145 Else
1146 If i = 1 Then
1150 Print #X, Space$(9) & "CallOuts: " & Format(i, "00") & " "
& gDebugStack(i)
1151 Else
1152 Print #X, Space$(9) & " " & Format(i, "00") & " "
& gDebugStack(i)
1153 End If
1154 End If
1155 End If
1156 Next i
1157 End If
1158 Close #X

1170 If theDisplaySwitc h = True Then
1171 If myVerboseSw = True Then
1172 If myErrorLine > 0 Then
1173 myMessage = " " & "... at line " & Str(myErrorLine ) & " in " &
Chr$(34) & gDebugStack(gSt ackPointer) & Chr$(34)
1174 Else
1175 myMessage = " " & "in " & Chr$(34) & gDebugStack(gSt ackPointer)
& Chr$(34)
1176 End If

1180 myMessage = myMessage & skipLine & "Error# " & Str(myErrorNumb er) &
": " & myErrorMessage
1181 myMessage = myMessage & skipLine & theSupplemental Message
1182 DoCmd.OpenForm "frmBugAlertVer bose", , , , , , myMessage
1183 Else
1184 DoCmd.OpenForm "frmBugAlertCon cise", , , , , , myErrorPath
1185 End If
1999 End If

bugAlert_xit:
On Error Resume Next
Close #X
ExitSub

bugAlert_err:
Select Case Err
Case cannotDoAtThisT ime
'Do nothing: There is probably a print dialog active, which prevents
opening the bugALert screen.
'Error has, however been writen to the error log...

Case Else
MsgBox "bugAlert() failed at line " & Str(Erl) & ", Error " & Str(Err) &
": " & Error$ & vbCrLf & "StackPoint er=" & Val(gStackPoint er) & vbCrLf & vbCrLf
& "Original error Info:" & vbCrLf & "Error " & Str(myErrorNumb er) & " at line "
& Str(myErrorLine ) & ": " & myErrorMessage & vbCrLf & theSupplemental Message,
48, "Error In Error Handler"
stackFlush
End Select
Resume bugAlert_xit
End Sub
Sub stackFlush()

' PURPOSE: Flush the debug stack to the log file in case we find it is
overloaded
' ACCEPTS: - A boolean telling whether-or-not to show a screen to the user
' - Supplemental text to be added to the log entry and shown on the
screen

1010 Dim myErrorLine As Long
Dim myErrorNumber As Long
Dim myErrorMessage As String

1011 myErrorLine = Erl 'Capture relevant info ASAP
1012 myErrorNumber = Err
1013 myErrorMessage = Error$

1014 On Error GoTo stackFlush_err

Dim X As Integer
Dim i As Integer
Dim L As Long
Dim myErrorPath As String
Dim myHeaderLine As String
Dim myAppVersion As String

Dim ParmValue As String

Const myOptionGroup = "ProgramPar ms"
Const cannotDoAtThisT ime = 2486

Dim skipLine As String
1020 skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & " "

1021 DoCmd.SetWarnin gs True

1030 ParmValue = String(255, 0)
1031 L = GetPrivateProfi leString(myOpti onGroup, "ErrorPath" , "{NotFound} ",
ParmValue, 255, SysCmd(acSysCmd IniFile))
1032 If L And Left(ParmValue, 10) <> "{NotFound} " Then
1033 myErrorPath = Left(ParmValue, L)
1034 Else
1035 myErrorPath = "C:\Error.t xt"
1036 End If

1050 X = FreeFile
1051 Open myErrorPath For Append As X

1060 Print #X,
"-----------------------------------------------------------------"
1061 Print #X, "<============= ==== STACK FLUSH
=============== =============== ===>"

1071 myHeaderLine = VBA.Format$(Now , "mm/dd/yy hh:nn:ss") & " Userid: " &
CurrentUser() & " on " & computerNameGet _bal()

1080 Print #X, myHeaderLine
1100 Print #X, " Proc: " & gDebugStack(gSt ackPointer)
1130 Print #X, ""

1140 If gStackPointer > 1 Then
1141 For i = 0 To gStackLimit
1142 If gDebugStack(i) <> "" Then
1143 If i = gStackPointer Then
1144 Print #X, Space$(9) & " " & Format(i, "00") & ">>" &
gDebugStack(i)
1145 Else
1146 If i = 1 Then
1150 Print #X, Space$(9) & "CallOuts: " & Format(i, "00") & " "
& gDebugStack(i)
1151 Else
1152 Print #X, Space$(9) & " " & Format(i, "00") & " "
& gDebugStack(i)
1153 End If
1154 End If
1155 End If
1156 Next i
1157 End If
1999 Close #X

stackFlush_xit:
On Error Resume Next
Close #X
Exit Sub

stackFlush_err:
Select Case Err
Case cannotDoAtThisT ime
'Do nothing: There is probably a print dialog active, which prevents
opening the stackFlush screen.
'Error has, however been writen to the error log...

Case Else
MsgBox "stackFlush () failed at line " & Str(Erl) & ", Error " & Str(Err)
& ": " & Error$ & vbCrLf & "StackPoint er=" & Val(gStackPoint er) & vbCrLf &
vbCrLf & "Original error Info:" & vbCrLf & "Error " & Str(myErrorNumb er) & " at
line " & Str(myErrorLine ) & ": " & myErrorMessage, 48, "Error In Error Handler"
End Select
Resume stackFlush_xit
End Sub
Sub aaTestBugAlert( )
debugStackPush mModuleName & ": aaTestBugAlert"
On Error GoTo aaTestBugAlert_ err

' PURPOSE: To supply a model for using the BugAlert routines and to demo the
routines
'
' NOTES: 1) Fire up a Debug window and type "aaTestBugAlert "

DoCmd.OpenForm "frmNon-Existant"

aaTestBugAlert_ xit:
debugStackPop
On Error Resume Next
Exit Sub

aaTestBugAlert_ err:
' bugAlert False, "This is the supplemental text...."
bugAlert True, "This is the supplemental text...."
Resume aaTestBugAlert_ xit
End Sub
Sub debugStackPop()
On Error GoTo debugStackPop_e rr

' PURPOSE: To pop the last procedure name off the top of the debug stack

Dim i As Integer

If gStackPointer <= gStackLimit Then
gDebugStack(gSt ackPointer) = ""
End If

gStackPointer = gStackPointer - 1

If gStackPointer < 0 Then
gStackPointer = 0
End If

debugStackPop_x it:
On Error Resume Next
Exit Sub

debugStackPop_e rr:
MsgBox "debugStackPop( ) failed. Error " & Str(Err) & ": " & Error$, 48, "Error
In Error Handler"
Resume debugStackPop_x it
End Sub
Function debugStackPrint ()
On Error GoTo debugStackPrint _err

Dim i As Integer

DoCmd.Hourglass True
Debug.Print "-------- Begin Debug Stack ---------"

For i = 1 To gStackPointer
Debug.Print VBA.Format$(i, "00") & ": " & gDebugStack(i)
Next i

Debug.Print "---------- End Debug Stack ---------"
DoCmd.Hourglass False

debugStackPrint _xit:
On Error Resume Next
Exit Function

debugStackPrint _err:
MsgBox "debugStackPrin t() failed. Error " & Str(Err) & ": " & Error$, 48,
"Error In Error Handler"
Resume debugStackPrint _xit
End Function
Sub debugStackPush( ByVal theProcedureNam e As String)
On Error GoTo debugStackPush_ err

' PURPOSE: To push a procedure name into the debug stack
' ACCEPTS: The procedure name
Dim i As Integer

gStackPointer = gStackPointer + 1

If gStackPointer <= gStackLimit Then
gDebugStack(gSt ackPointer) = theProcedureNam e
Else
gDebugStack(gSt ackLimit + 2) = theProcedureNam e
End If

debugStackPush_ xit:
On Error Resume Next
Exit Sub

debugStackPush_ err:
MsgBox "debugStackPush () failed. Error " & Str(Err) & ": " & Error$, 48,
"Error In Error Handler"
Resume debugStackPush_ err
End Sub
Private Function computerNameGet _bal() As String
On Error GoTo computerNameGet _bal_err

' PURPOSE: To extract the name of the user's PC from via Windows API instead of
environment variables
' RETURNS: Name of user's PC or a blank string

Dim L As Long
Dim lpBuffer As String * 255
Dim myComputerName As String

L = GetComputerName _bal(lpBuffer, 255)
myComputerName = stripNulls_bal( lpBuffer)

computerNameGet _bal = myComputerName

computerNameGet _bal_xit:
On Error Resume Next
Exit Function

computerNameGet _bal_err:
MsgBox "computerNameGe t_bal() failed. Error " & Str(Err) & ": " & Error$, 48,
"Error In Error Handler"
Resume computerNameGet _bal_xit
End Function
Private Function stripNulls_bal( theOriginalStri ng As String)
On Error GoTo stripNulls_bal_ err

If InStr(1, theOriginalStri ng, Chr(0), vbTextCompare) Then
theOriginalStri ng = Mid(theOriginal String, 1, InStr(theOrigin alString,
Chr(0)) - 1)
End If

stripNulls_bal = theOriginalStri ng

stripNulls_bal_ xit:
On Error Resume Next
Exit Function

stripNulls_bal_ err:
MsgBox "stipNulls( ) failed. Error " & Str(Err) & ": " & Error$, 48, "Error In
Error Handler"
Resume stripNulls_bal_ xit
End Function
Private Function currentVersionG et_bal() As String
1001 On Error GoTo currentVersionG et_bal_err

' PURPOSE: To retrieve the current version of the app
' RETURNS: Current version of the app as a formatted number. e.g. "5.31"
' USES: A special application-resident table named "---------- Program
Changes ----------"
'
' NOTES: 1) The table's name is designed to float it to the top of the table
list and call attention
' to the fact that is something out-of-the-ordinary table-wise

1010 Dim myRS As DAO.Recordset

Static myCurrentVersio n As String

1060 If Len(myCurrentVe rsion) = 0 Then
1160 Set myRS = CurrentDb().Ope nRecordset("SEL ECT Max([---------- Program
Changes ----------].versionNumber) AS MaxOfversionNum ber FROM [----------
Program Changes ----------];", dbOpenSnapshot)
1180 myCurrentVersio n = "v" & VBA.Format$(Nz( myRS!MaxOfversi onNumber,
"0.00"))
1240 End If

1999 currentVersionG et_bal = myCurrentVersio n

currentVersionG et_bal_xit:
On Error Resume Next
myRS.Close
Set myRS = Nothing
Exit Function

currentVersionG et_bal_err:
MsgBox "currentVersion Get() failed at line " & Str(Erl) & ", Error " & Str(Err)
& ": " & Error$, 48, "Error In Error Handler"
Resume currentVersionG et_bal_xit
End Function
Sub stackClear()

' PURPOSE: To clear the debug stack. Intended for use while debugging.

Dim i As Integer

If gStackPointer > 1 Then
For i = 0 To gStackLimit
If gDebugStack(i) <> "" Then
gDebugStack(i) = ""
End If
Next i
End If

gStackPointer = 0

stackClear_xit:
On Error Resume Next
Exit Sub

stackClear_err:
Resume stackClear_xit
End Sub
Private Function windozeIdGet_ba l()
On Error GoTo windozeIdGet_ba l_err

' PURPOSE: To get the current Windows UserID
' RETURNS: ID or error message

Dim myBuffer As String * 255
Dim myUserName As String

GetUserName_bal myBuffer, Len(myBuffer) 'Get the
user name
myUserName = Left(Trim(myBuf fer), InStr(myBuffer, Chr(0)) - 1) 'Trim excess
characters

If Len(myUserName) > 0 Then
windozeIdGet_ba l = myUserName
Else
windozeIdGet_ba l "windozeIdGet_b al() Unable to get Windows UserID"
End If

windozeIdGet_ba l_xit:
On Error Resume Next
Exit Function

windozeIdGet_ba l_err:
MsgBox "stipNulls( ) failed. Error " & Str(Err) & ": " & Error$, 48, "Error In
Error Handler"
Resume windozeIdGet_ba l_xit
End Function
----------------------------------------------
--
PeteCresswell
Nov 12 '05 #2
Surely -- code it right in. Some third party tools hold it in a compile-time
variable and you can insert that variable. Check a free tool of this kind
CodeWrite2 at MVP Arvin Meyer's site, http://www.datastrat.com.

Larry Linson
Microsoft Access MVP
"deko" <dj****@hotmail .com> wrote in message
news:Is******** **********@news svr25.news.prod igy.com...
I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description &
vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible to get this...)

How about offloading this to a module so I don't have to type it out every
time:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...

Nov 12 '05 #3
On Wed, 10 Dec 2003 22:52:24 GMT, "deko" <dj****@hotmail .com> wrote:

Literally: no.
Therefore in VBA people often resort to secondary solutions. For
example at the top of each function you "Push" the name of the current
function on a stack, and at the bottom you "Pop" it off again. This
boilerplate code can be added by writing some code that works with the
Module object.

In .NET you *do* have access to a Stack object, so you can do what you
ask for, and more.

-Tom.

I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description &
vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible to
get this...)

How about offloading this to a module so I don't have to type it out every
time:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...


Nov 12 '05 #4
You might want an "On Error Resume Next" as the first thing in your
Exit section.

Exit_Here:
On Error Resume Next
'do some stuff here
Exit Sub

Reason: if an error gets raised in the Exit section, your
ErrorHandler will go into an infinite loop.

-Matt

On Wed, 10 Dec 2003 22:52:24 GMT, "deko" <dj****@hotmail .com> wrote:
Exit_Here:
Exit Sub


Nov 12 '05 #5
good point...

"Matthew Sullivan" <Ma**@NoSpam.co m> wrote in message
news:lk******** *************** *********@4ax.c om...
You might want an "On Error Resume Next" as the first thing in your
Exit section.

Exit_Here:
On Error Resume Next
'do some stuff here
Exit Sub

Reason: if an error gets raised in the Exit section, your
ErrorHandler will go into an infinite loop.

-Matt

On Wed, 10 Dec 2003 22:52:24 GMT, "deko" <dj****@hotmail .com> wrote:
Exit_Here:
Exit Sub

Nov 12 '05 #6
Have a look at MZ-Tools. This will automate writing error handlers for you
an dyou can edit the error hanldler it inserts.

Plus it does an awful lot of other things that you will find useful.

http://www.mztools.com/
Terry

"deko" <dj****@hotmail .com> wrote in message
news:Is******** **********@news svr25.news.prod igy.com...
I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description &
vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible to get this...)

How about offloading this to a module so I don't have to type it out every
time:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...

Nov 12 '05 #7
thanks for the tip... will check it out...

"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:2q******** ************@ka roo.co.uk...
Have a look at MZ-Tools. This will automate writing error handlers for you
an dyou can edit the error hanldler it inserts.

Plus it does an awful lot of other things that you will find useful.

http://www.mztools.com/
Terry

"deko" <dj****@hotmail .com> wrote in message
news:Is******** **********@news svr25.news.prod igy.com...
I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description & vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible

to
get this...)

How about offloading this to a module so I don't have to type it out every time:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...


Nov 12 '05 #8
Ma**@NoSpam.com (Matthew Sullivan) wrote in
<lk************ *************** *****@4ax.com>:
You might want an "On Error Resume Next" as the first thing in
your Exit section.

Exit_Here:
On Error Resume Next
'do some stuff here
Exit Sub

Reason: if an error gets raised in the Exit section, your
ErrorHandler will go into an infinite loop.


Er, I've never written a single error handler with that in it, nor
ever seen one in any of the Access books I've used, and I've never
encountered an error in an error handler. Of course, the only thing
I ever do in an error handler is to display an error message and
redirect to the appropriate location in code.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #9
Thanks... you may be getting me in over my head, but I'll see if I can get
that module to work in my mdb...

for now, I've come up with this:

Exit_Here:
On Error Resume Next
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
Dim fn As String
fn = Me.Form.Name
modHandler.Erms g (fn)
Resume Exit_Here
End Select

Here is code for modHandler:

Public Sub Ermsg (fn)
MsgBox "Error Number " & Err.Number & ": " & Err.Description & vbCrLf &
fn
End Sub

the next step is putting this into every procedure in the database...
perhaps there is a way to automate this... ?
"(Pete Cresswell)" <x@y.z> wrote in message
news:gi******** *************** *********@4ax.c om...
RE/
I use this convention frequently:

Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select

Is there a way to include the current procedure name on Case Else?

perhaps something like this:

Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description &vbCrLf & _
Me.ProcedureNam e & Me.Form
Resume Exit_Here
End Select
(note: "Me.ProcedureNa me" is pseudo code - I don't know if it's possible toget this...)

How about offloading this to a module so I don't have to type it out everytime:

Case Else
strP = Me!Procedure
strF = Me.Form
modErr.caseElse
End Select

thoughts ? suggestions ?

Thanks in advance...

Every routine I write is within the skeleton below.

"DebugStackPush ()", "DebugStackPop( )", and "BugAlert() " are all in
a module I call "basBugAler t".

The Push/Pop routines push the routine's name into an array/pop it out.

"BugAlert" refers to the array to get a trace of where we've been
just before the error popped. It then displays a little error screen to
the user and logs the error and the trace in a .TXT file.

The module is at the end of this note. If somebody can make it a little
better, I'd appreciate a copy of the improved code.

If you're trying to compile it and the line breaks are making you crazy,

post a reply and I'll email the .bas file to you.

-----------------------------------------------
Whatever()
DebugStackPush mModulename & ": Whatever"
On Error GoTo Whatever_err

' PURPOSE: To do whatever
' ACCEPTS:
' RETURNS:
'
' NOTES: 1).....
(code goes here...)

Whatever_xit:
DebugStackPop
On Error Resume Next
(release pointers, close recordsets)
Exit Sub

Whatever_err:
BugAlert True, ""
(optionally case out on Err if some errors are acceptable)
Resume Whatever_xit
----------------------------------------------
Option Compare Database 'Use database order for string comparisons
Option Explicit

' This module contains the routines used to trap/log errors and
' show the "bugAlert" screen.

' REQUIRES: 1) A table named "---------- Program Changes ----------" in the app '
' 2) A global constant:
' Global Const gIniGroupName = "TretsParms "
'
' 3) Two forms:
' frmBugAlertConc ise
' frmBugAlertVerb ose
'
' NOTES: 1) To avoid loops, most of these routines should be using their own own error trapping,
' which would be limited to just showing message boxes - as opposed to potentially-recursive
' calls to debugStackPush( ) and debugStackPop()

Const mModuleName = "basBugAler t"

Global Const gStackLimit = 50

Const debugStackTotal Size = 52
Global gDebugStack(deb ugStackTotalSiz e)

Global gStackPointer As Integer

Global gErrorMessage As String 'For any calling routine that wants to trap the error message before bugAlert munches on it.
Global gErrorLocation As String 'Ditto above, but contains name of routine

Private Declare Function GetComputerName _bal Lib "kernel32" Alias
"GetComputerNam eA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName_bal Lib "advapi32.d ll" Alias "GetUserNam eA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetPrivateProfi leString Lib "kernel32" Alias
"GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedStrin g As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Sub bugAlert(ByVal theDisplaySwitc h As Integer, ByVal theSupplemental Message As String)

' PURPOSE: To log an error and, maybe, show an error screen to the user
' ACCEPTS: - A boolean telling whether-or-not to show a screen to the user ' - Supplemental text to be added to the log entry and shown on the screen
' USES: - An optional .INI file parm called "myErrorPat h", which tells where to write the error
' - An optional .INI file parm called "VerboseErrorDi splay" that tells us if we want
' to show frmBugAlertVerb ose
'
' NOTES: 1) We are in error mode: anything could be happening.
' Therefore error trapping is limited to a messagebox.
' 2) We assume that the calling routine, after invoking this, will gracefully proceed
' to it's "Exit" coding and pop the debug stack on the way out. ' 3) Note that out "On Error" statement isn't until *After* we've captured error info.
' 4) Setting the display switch to False and suppling a supplemental message allows the programmer
' to record things in the error log which did not result from
errors in the technical sense.
' e.g. bugAlert, False, "This sentence gets written to the error log"
' 5) If there is no path specified in the .INI file, we write to the root of C:

1001 Dim myErrorLine As Long
Dim myErrorNumber As Long
Dim myErrorMessage As String

1002 myErrorLine = Erl 'Capture relevant info ASAP
1003 myErrorNumber = Err
1004 myErrorMessage = Error$
1005 gErrorMessage = Error$
1006 gErrorLocation = gDebugStack(gSt ackPointer)

1007 On Error GoTo bugAlert_err
1008 DoCmd.Echo True 'In case it was turned off elsewhere
Dim v As Variant
Dim X As Integer
Dim myMessage As String
Dim myTimeStamp As String
Dim i As Integer
Dim L As Long
Dim myErrorPath As String
Dim myHeaderLine As String
Dim myAppVersion As String
Dim myVerboseSw As Boolean

Dim ParmValue As String

Const cannotDoAtThisT ime = 2486

Dim skipLine As String

1010 skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & " "

1011 DoCmd.SetWarnin gs True

1020 ParmValue = String(255, 0)
1021 L = GetPrivateProfi leString(gIniGr oupName, "ErrorLogPa th", "{NotFound} ", ParmValue, 255, SysCmd(acSysCmd IniFile))
1022 If L And Left(ParmValue, 10) <> "{NotFound} " Then
1023 myErrorPath = Left(ParmValue, L)
1024 Else
1025 myErrorPath = CurrentDb().Nam e
1026 If Right(myErrorPa th, 4) = ".mdb" Then
1027 myErrorPath = Left(myErrorPat h, Len(myErrorPath ) - 4)
1028 End If
1029 myErrorPath = myErrorPath & ".Errors.tx t"
1030 End If

1040 ParmValue = String(255, 0)
1041 L = GetPrivateProfi leString(gIniGr oupName, "VerboseErrorDi splay",
"{NotFound} ", ParmValue, 255, SysCmd(acSysCmd IniFile))
1042 If L And Left(ParmValue, 10) <> "{NotFound} " Then
1043 If (Left(ParmValue , L) = "True") Or (Left(ParmValue , L) = "Yes") Then 1044 myVerboseSw = True
1045 End If
1046 End If

1049 myVerboseSw = True 'FORCE VERBOSE ERROR DISPLAY

1050 X = FreeFile
1051 Open myErrorPath For Append As X

1060 Print #X,
"-----------------------------------------------------------------"

1070 myAppVersion = currentVersionG et_bal
1071 myHeaderLine = VBA.Format$(Now , "mm/dd/yy hh:nn:ss") & myAppVersion & " Userid: " & windozeIdGet_ba l() & " on " & computerNameGet _bal()

1080 Print #X, myHeaderLine

1090 If theDisplaySwitc h = False Then
1091 Print #X, "(ERROR SCREEN SUPPRESSED)"
1092 End If

1100 Print #X, " Proc: " & gDebugStack(gSt ackPointer)

1101 If myErrorNumber <> 0 Then
1102 If myErrorLine > 0 Then
1103 Print #X, String(9, " ") & "Line " & VBA.Format$(myE rrorLine,
"000000") & " " & VBA.Format$(myE rrorNumber, "0000") & ": " & myErrorMessage 1104 Else
1105 Print #X, String(13, " ") & VBA.Format$(myE rrorNumber, "0000") & ": " & myErrorMessage
1109 End If
1110 Else
1111 If myErrorLine > 0 Then
1112 Print #X, String(9, " ") & "Line " & VBA.Format$(myE rrorLine,
"000000") & ": "
1113 Else
1114 Print #X, String(13, " ")
1115 End If
1119 End If

1120 If theSupplemental Message <> "" Then
1121 Print #X, Space$(19) & theSupplemental Message
1122 End If

1130 Print #X, ""

1140 If gStackPointer > 1 Then
1141 For i = 0 To gStackLimit
1142 If gDebugStack(i) <> "" Then
1143 If i = gStackPointer Then
1144 Print #X, Space$(9) & " " & Format(i, "00") & ">>" & gDebugStack(i)
1145 Else
1146 If i = 1 Then
1150 Print #X, Space$(9) & "CallOuts: " & Format(i, "00") & " " & gDebugStack(i)
1151 Else
1152 Print #X, Space$(9) & " " & Format(i, "00") & " " & gDebugStack(i)
1153 End If
1154 End If
1155 End If
1156 Next i
1157 End If
1158 Close #X

1170 If theDisplaySwitc h = True Then
1171 If myVerboseSw = True Then
1172 If myErrorLine > 0 Then
1173 myMessage = " " & "... at line " & Str(myErrorLine ) & " in " & Chr$(34) & gDebugStack(gSt ackPointer) & Chr$(34)
1174 Else
1175 myMessage = " " & "in " & Chr$(34) & gDebugStack(gSt ackPointer) & Chr$(34)
1176 End If

1180 myMessage = myMessage & skipLine & "Error# " & Str(myErrorNumb er) & : " & myErrorMessage
1181 myMessage = myMessage & skipLine & theSupplemental Message
1182 DoCmd.OpenForm "frmBugAlertVer bose", , , , , , myMessage
1183 Else
1184 DoCmd.OpenForm "frmBugAlertCon cise", , , , , , myErrorPath
1185 End If
1999 End If

bugAlert_xit:
On Error Resume Next
Close #X
Exit Sub

bugAlert_err:
Select Case Err
Case cannotDoAtThisT ime
'Do nothing: There is probably a print dialog active, which prevents opening the bugALert screen.
'Error has, however been writen to the error log...

Case Else
MsgBox "bugAlert() failed at line " & Str(Erl) & ", Error " & Str(Err) & ": " & Error$ & vbCrLf & "StackPoint er=" & Val(gStackPoint er) & vbCrLf & vbCrLf & "Original error Info:" & vbCrLf & "Error " & Str(myErrorNumb er) & " at line " & Str(myErrorLine ) & ": " & myErrorMessage & vbCrLf & theSupplemental Message, 48, "Error In Error Handler"
stackFlush
End Select
Resume bugAlert_xit
End Sub
Sub stackFlush()

' PURPOSE: Flush the debug stack to the log file in case we find it is
overloaded
' ACCEPTS: - A boolean telling whether-or-not to show a screen to the user ' - Supplemental text to be added to the log entry and shown on the screen

1010 Dim myErrorLine As Long
Dim myErrorNumber As Long
Dim myErrorMessage As String

1011 myErrorLine = Erl 'Capture relevant info ASAP
1012 myErrorNumber = Err
1013 myErrorMessage = Error$

1014 On Error GoTo stackFlush_err

Dim X As Integer
Dim i As Integer
Dim L As Long
Dim myErrorPath As String
Dim myHeaderLine As String
Dim myAppVersion As String

Dim ParmValue As String

Const myOptionGroup = "ProgramPar ms"
Const cannotDoAtThisT ime = 2486

Dim skipLine As String
1020 skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10) & " "

1021 DoCmd.SetWarnin gs True

1030 ParmValue = String(255, 0)
1031 L = GetPrivateProfi leString(myOpti onGroup, "ErrorPath" , "{NotFound} ", ParmValue, 255, SysCmd(acSysCmd IniFile))
1032 If L And Left(ParmValue, 10) <> "{NotFound} " Then
1033 myErrorPath = Left(ParmValue, L)
1034 Else
1035 myErrorPath = "C:\Error.t xt"
1036 End If

1050 X = FreeFile
1051 Open myErrorPath For Append As X

1060 Print #X,
"-----------------------------------------------------------------"
1061 Print #X, "<============= ==== STACK FLUSH
=============== =============== ===>"

1071 myHeaderLine = VBA.Format$(Now , "mm/dd/yy hh:nn:ss") & " Userid: " &
CurrentUser() & " on " & computerNameGet _bal()

1080 Print #X, myHeaderLine
1100 Print #X, " Proc: " & gDebugStack(gSt ackPointer)
1130 Print #X, ""

1140 If gStackPointer > 1 Then
1141 For i = 0 To gStackLimit
1142 If gDebugStack(i) <> "" Then
1143 If i = gStackPointer Then
1144 Print #X, Space$(9) & " " & Format(i, "00") & ">>" & gDebugStack(i)
1145 Else
1146 If i = 1 Then
1150 Print #X, Space$(9) & "CallOuts: " & Format(i, "00") & " " & gDebugStack(i)
1151 Else
1152 Print #X, Space$(9) & " " & Format(i, "00") & " " & gDebugStack(i)
1153 End If
1154 End If
1155 End If
1156 Next i
1157 End If
1999 Close #X

stackFlush_xit:
On Error Resume Next
Close #X
Exit Sub

stackFlush_err:
Select Case Err
Case cannotDoAtThisT ime
'Do nothing: There is probably a print dialog active, which prevents opening the stackFlush screen.
'Error has, however been writen to the error log...

Case Else
MsgBox "stackFlush () failed at line " & Str(Erl) & ", Error " & Str(Err) & ": " & Error$ & vbCrLf & "StackPoint er=" & Val(gStackPoint er) & vbCrLf &
vbCrLf & "Original error Info:" & vbCrLf & "Error " & Str(myErrorNumb er) & " at line " & Str(myErrorLine ) & ": " & myErrorMessage, 48, "Error In Error Handler" End Select
Resume stackFlush_xit
End Sub
Sub aaTestBugAlert( )
debugStackPush mModuleName & ": aaTestBugAlert"
On Error GoTo aaTestBugAlert_ err

' PURPOSE: To supply a model for using the BugAlert routines and to demo the routines
'
' NOTES: 1) Fire up a Debug window and type "aaTestBugAlert "

DoCmd.OpenForm "frmNon-Existant"

aaTestBugAlert_ xit:
debugStackPop
On Error Resume Next
Exit Sub

aaTestBugAlert_ err:
' bugAlert False, "This is the supplemental text...."
bugAlert True, "This is the supplemental text...."
Resume aaTestBugAlert_ xit
End Sub
Sub debugStackPop()
On Error GoTo debugStackPop_e rr

' PURPOSE: To pop the last procedure name off the top of the debug stack

Dim i As Integer

If gStackPointer <= gStackLimit Then
gDebugStack(gSt ackPointer) = ""
End If

gStackPointer = gStackPointer - 1

If gStackPointer < 0 Then
gStackPointer = 0
End If

debugStackPop_x it:
On Error Resume Next
Exit Sub

debugStackPop_e rr:
MsgBox "debugStackPop( ) failed. Error " & Str(Err) & ": " & Error$, 48, "Error In Error Handler"
Resume debugStackPop_x it
End Sub
Function debugStackPrint ()
On Error GoTo debugStackPrint _err

Dim i As Integer

DoCmd.Hourglass True
Debug.Print "-------- Begin Debug Stack ---------"

For i = 1 To gStackPointer
Debug.Print VBA.Format$(i, "00") & ": " & gDebugStack(i)
Next i

Debug.Print "---------- End Debug Stack ---------"
DoCmd.Hourglass False

debugStackPrint _xit:
On Error Resume Next
Exit Function

debugStackPrint _err:
MsgBox "debugStackPrin t() failed. Error " & Str(Err) & ": " & Error$, 48, "Error In Error Handler"
Resume debugStackPrint _xit
End Function
Sub debugStackPush( ByVal theProcedureNam e As String)
On Error GoTo debugStackPush_ err

' PURPOSE: To push a procedure name into the debug stack
' ACCEPTS: The procedure name
Dim i As Integer

gStackPointer = gStackPointer + 1

If gStackPointer <= gStackLimit Then
gDebugStack(gSt ackPointer) = theProcedureNam e
Else
gDebugStack(gSt ackLimit + 2) = theProcedureNam e
End If

debugStackPush_ xit:
On Error Resume Next
Exit Sub

debugStackPush_ err:
MsgBox "debugStackPush () failed. Error " & Str(Err) & ": " & Error$, 48,
"Error In Error Handler"
Resume debugStackPush_ err
End Sub
Private Function computerNameGet _bal() As String
On Error GoTo computerNameGet _bal_err

' PURPOSE: To extract the name of the user's PC from via Windows API instead of environment variables
' RETURNS: Name of user's PC or a blank string

Dim L As Long
Dim lpBuffer As String * 255
Dim myComputerName As String

L = GetComputerName _bal(lpBuffer, 255)
myComputerName = stripNulls_bal( lpBuffer)

computerNameGet _bal = myComputerName

computerNameGet _bal_xit:
On Error Resume Next
Exit Function

computerNameGet _bal_err:
MsgBox "computerNameGe t_bal() failed. Error " & Str(Err) & ": " & Error$, 48, "Error In Error Handler"
Resume computerNameGet _bal_xit
End Function
Private Function stripNulls_bal( theOriginalStri ng As String)
On Error GoTo stripNulls_bal_ err

If InStr(1, theOriginalStri ng, Chr(0), vbTextCompare) Then
theOriginalStri ng = Mid(theOriginal String, 1, InStr(theOrigin alString, Chr(0)) - 1)
End If

stripNulls_bal = theOriginalStri ng

stripNulls_bal_ xit:
On Error Resume Next
Exit Function

stripNulls_bal_ err:
MsgBox "stipNulls( ) failed. Error " & Str(Err) & ": " & Error$, 48, "Error In Error Handler"
Resume stripNulls_bal_ xit
End Function
Private Function currentVersionG et_bal() As String
1001 On Error GoTo currentVersionG et_bal_err

' PURPOSE: To retrieve the current version of the app
' RETURNS: Current version of the app as a formatted number. e.g. "5.31" ' USES: A special application-resident table named "---------- Program
Changes ----------"
'
' NOTES: 1) The table's name is designed to float it to the top of the table list and call attention
' to the fact that is something out-of-the-ordinary table-wise

1010 Dim myRS As DAO.Recordset

Static myCurrentVersio n As String

1060 If Len(myCurrentVe rsion) = 0 Then
1160 Set myRS = CurrentDb().Ope nRecordset("SEL ECT Max([---------- Program Changes ----------].versionNumber) AS MaxOfversionNum ber FROM [----------
Program Changes ----------];", dbOpenSnapshot)
1180 myCurrentVersio n = "v" & VBA.Format$(Nz( myRS!MaxOfversi onNumber,
"0.00"))
1240 End If

1999 currentVersionG et_bal = myCurrentVersio n

currentVersionG et_bal_xit:
On Error Resume Next
myRS.Close
Set myRS = Nothing
Exit Function

currentVersionG et_bal_err:
MsgBox "currentVersion Get() failed at line " & Str(Erl) & ", Error " & Str(Err) & ": " & Error$, 48, "Error In Error Handler"
Resume currentVersionG et_bal_xit
End Function
Sub stackClear()

' PURPOSE: To clear the debug stack. Intended for use while debugging.

Dim i As Integer

If gStackPointer > 1 Then
For i = 0 To gStackLimit
If gDebugStack(i) <> "" Then
gDebugStack(i) = ""
End If
Next i
End If

gStackPointer = 0

stackClear_xit:
On Error Resume Next
Exit Sub

stackClear_err:
Resume stackClear_xit
End Sub
Private Function windozeIdGet_ba l()
On Error GoTo windozeIdGet_ba l_err

' PURPOSE: To get the current Windows UserID
' RETURNS: ID or error message

Dim myBuffer As String * 255
Dim myUserName As String

GetUserName_bal myBuffer, Len(myBuffer) 'Get the user name
myUserName = Left(Trim(myBuf fer), InStr(myBuffer, Chr(0)) - 1) 'Trim excess characters

If Len(myUserName) > 0 Then
windozeIdGet_ba l = myUserName
Else
windozeIdGet_ba l "windozeIdGet_b al() Unable to get Windows UserID"
End If

windozeIdGet_ba l_xit:
On Error Resume Next
Exit Function

windozeIdGet_ba l_err:
MsgBox "stipNulls( ) failed. Error " & Str(Err) & ": " & Error$, 48, "Error In Error Handler"
Resume windozeIdGet_ba l_xit
End Function
----------------------------------------------
--
PeteCresswell

Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
49580
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
136
9425
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
4
2000
by: Sandy | last post by:
Hello - I read an interesting article on the web wherein the author states he doesn't handle too many errors at page level, but handles them at the application level. He further goes on to show how error logging can be incorporated using a Sql Server log with an additional text log in case Sql Server was down. My inclination after reading the article is to use Try-Catch-Finally as little as possible (tends to slow things if you have...
0
2645
by: Benny Ng | last post by:
Hi,All, When i deploy Enterprise library with my application ,i used XCOPY to deploy it into my test server. But when application runs, shown some error related registry. (But actually I haven't any method or component to wrote registry) After I used "InstallUtil" to registry Enterprise Library (those DLLs) to the deployment server, the application runs smoothly. Now I wonder why i need to registry those Enterprise Library DLLs into
10
3471
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
10
1697
by: Fao, Sean | last post by:
A guy I know never refactors his code and insists on putting everything in an event handler. For example, he does some initialization of a DataGrid in the ItemDataBound event handler (which is actually the wrong place for his initialization, anyhow, because it has *nothing* to do with the items being bound, but that's another topic, altogether). At any rate, some times, it's necessary to "refresh" the control to take advantage of an...
1
2219
by: Phil Powell | last post by:
&lt;input type="submit" name="delete_student" value="Delete Applicant" onClick="setSubmitVal(this); return willDeleteApplicant('O&amp;#039;Connor, Kerry B');"&gt; This HTML tag causes Javascript errors in IE 7+ and in Mozilla; seems to be OK in Firefox 1.0 for Linux. This is a time-sensitive issue that I can't seem to resolve, could someone come up with a quickie for me in this case? It seems the student's name is breaking things in Javascript...
3
2234
by: alvinwoon | last post by:
Hi guys, I find it frustrating that I need to sniff out IE to make event handler for the form's select element work across different browsers. Here's a summary of what I have right now: var select = /*get the form select element*/ var option = /*get all the option elements*/ if(document.all){
0
1250
by: joshfink | last post by:
Hey guys, I am writing an application where I want to follow the best practices on error handling. This is what I have: I created an enum for various issues that could happen within the DAL... INSERTFAILED, INSERTSUCCESSFUL etc... I am setting this enum to a property of the dal for the object to access after the dal is done with whatever method I call... get, getAll, update, insert, delete, etc... The object can then access...
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.