Is there a way to get debug.print to print the current line number of the code? (similar to Debug.Print "Test " vbCodeLineNumber & ": " & varName)
thanks
Is there a way to get debug.print to print the current line number of the code? (similar to Debug.Print "Test " vbCodeLineNumber & ": " & varName)
thanks
TommySzalapski wrote:
> Is there a way to get debug.print to print the current line number of
> the code? (similar to Debug.Print "Test " vbCodeLineNumber & ": " &
> varName)
>
> thanks
>
>
I you enable line numbers in a function and then raise an error from
that function, you can get the line number, so:
Option Explicit
Private Const LOG_VARIABLE As Long = vbObjectError + 1
Sub LogVariable(varName As String, varValue As String)
Dim vval
vval = Split(varName, "::")
Debug.Print vval(0) & "(" & vval(2) & ") " & vval(1) & " = " & varValue
End Sub
Sub Test()
10 On Error GoTo Failed
15 Dim MyVar As String
20 MyVar = "Variable has been set"
30 Err.Raise LOG_VARIABLE, "Test::MyVar", MyVar
40 Exit Sub
45 Failed:
50 If Err.Number = LOG_VARIABLE Then
60 LogVariable Err.Source & "::" & Erl, Err.Description
70 Resume Next
80 End If
90 Err.Raise Err.Number, Err.Source, Err.Description
End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks