Erl will give you the line number. As far as what sub your in, I put a separate error handler in each sub. Maybe someone else has a better solution far that part.
If your aim is to generate an error message that tells you which routine an error occured in, then the only way is to have an error handler in each routine (I believe).
The way I report errors is to include the Me.Name property in the error message (this gives the form name), then the Routine name, then the line number.
Eg, in Form_Load:
ErrorHandler:
MsgBox "Error in " & Me.Name & " in Form_Load, line " & Erl
Many people think that line numbers went out with the Ark but for debugging apps that clients are using I find them really useful. I wrote the following code to add and remove line numbers from code, if it's any use.
It takes into account conditional compilation statements, and other VB commands which can't be prefixed with a line number.
To use it, copy your source code into Clipboard then run this project, you can then choose whether to add or remove line numbers. The resulting code is copied back into clipboard so you can paste it back over the top of your original selection.
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "Line Numbers - by andy.groom@dial.pipex.com"
ClientHeight = 6375
ClientLeft = 1665
ClientTop = 1785
ClientWidth = 8790
BeginProperty Font
Name = "Arial"
Size = 8.25
Charset = 0
Weight = 400
EndProperty
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6375
ScaleWidth = 8790
ShowInTaskbar = 0 'False
Begin VB.CommandButton b_Del
Caption = "Remove line numbers"
Height = 495
Left = 6915
TabIndex = 2
Top = 750
Width = 1740
End
Begin VB.CommandButton b_Add
Caption = "Add line numbers"
Height = 495
Left = 6915
TabIndex = 1
Top = 165
Width = 1740
End
Begin VB.TextBox t_Code
BeginProperty Font
Name = "Lucida Console"
Size = 9
Charset = 0
Weight = 400
EndProperty
Height = 6075
Left = 120
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Text = "frm_LineNumbers.frx":0000
Top = 150
Width = 6675
End
End
Const NumSpace = 4 ' Number of padding spaces allowed for line numbers at the start of each line
Private Sub b_Add_Click()
Dim Conditional As Boolean
Dim Continuation As Boolean
If (Left$(Trim$(l$), 1) = "#" Then Conditional = Not Conditional
If (Conditional = False) Then
ln$ = Left$(l$, NumSpace)
If (ln$ = Space$(NumSpace)) Then
l$ = Mid$(l$, 5) & vbCrLf
Else
If (IsNumeric(ln$) = True) Then
l$ = Mid$(l$, NumSpace + 1) & vbCrLf
Else
l$ = l$ & vbCrLf
End If
End If
Else
l$ = Mid$(l$, 5) & vbCrLf
End If
If (Len(l$) < 3) Then
Continuation = False
Else
Continuation = (Mid$(l$, Len(l$) - Len(vbCrLf), 1) = "_"
End If
NewN$ = NewN$ & l$
Loop
t_Code.Text = NewN$
Clipboard.Clear
Clipboard.SetText NewN$
b_Del.Enabled = True
End Sub
Private Sub Form_Load()
n$ = Clipboard.GetText
t_Code.Text = n$
End Sub
- Andy
_______________________________
"On a clear disk you can seek forever"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.