+ Reply to Thread
Results 1 to 2 of 2

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

  1. #1
    Registered User
    Join Date
    07-25-2005
    Posts
    62

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

    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

  2. #2
    David Welch
    Guest

    Re: 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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1