ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Debug.Print "Test " vbCodeLineNumber & ": " & varName (https://www.excelbanter.com/excel-programming/336150-debug-print-test-vbcodelinenumber-varname.html)

TommySzalapski[_32_]

Debug.Print "Test " vbCodeLineNumber & ": " & varName
 

Is there a way to get debug.print to print the current line number o
the code? (similar to Debug.Print "Test " vbCodeLineNumber & ": "
varName)

thank

--
TommySzalapsk
-----------------------------------------------------------------------
TommySzalapski's Profile: http://www.excelforum.com/member.php...fo&userid=2556
View this thread: http://www.excelforum.com/showthread.php?threadid=39216


David Welch[_2_]

Debug.Print "Test " vbCodeLineNumber & ": " & varName
 
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


All times are GMT +1. The time now is 12:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com