How Can We Return the Last Line Number Executed by A Program

Discussion in 'AutoCAD' started by matt_1ca, Mar 3, 2005.

  1. matt_1ca

    matt_1ca Guest

    I am trying to to write a debugger for a VB executable program that I am using to manipulate Autocad -- I have all the elements but while trying to put them together I realize that I am missing one important thing. And that is the ability to recover the last line executed by the executable code.

    I know I read somewhere many years ago how it can be done from Access VBA so I am assuming therefore that it can also be done in VB as well.

    Any suggestion you might have on this is welcome and
    thanks for all the kind help you can extend.

    Matt
     
    matt_1ca, Mar 3, 2005
    #1
  2. matt_1ca

    matt_1ca Guest

    No no no, sorry, correction, its not the last line executed by a code -- but its rather the current line number executed by a program at any given time that I am interested in having the ability to grab.

    Gratefully,
    Matt
     
    matt_1ca, Mar 3, 2005
    #2
  3. Hi Matt,

    It's early days yet, but I would not expect to find skills in writing
    debuggers away from the seriously high level programming community.

    You may care to search the web for newsgroups where readers are likely to
    have these skills.

    It would be worth joining the ADN if there are AutoCAD specific issues
    associated with the proposed operation of the debugger.
    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Mar 3, 2005
    #3
  4. matt_1ca

    Tim Arheit Guest

    It's pretty easy. First you have to number the lines of your code
    (there are utilities that will do this for you, google should turn up
    something, or email me and I'll send you a one.)

    Then in your error handling routines the line number is returned by
    erl().

    Example

    Public Sub MyFunction
    1 On Error Goto ErrorHandle
    2 Debug.Print "No Error"
    3 Debug.Print "Error Here " & cstr(100/0)
    4 Exit Sub

    ErrorHandle:
    call MsgBox("Error On Line: " & cstr(erl) & vbcrlf &
    err.Description)
    End Sub

    The above shoud show a message box showing the error 'Divide by 0' on
    line 3. This will work in VB as well as VBA

    -Tim
     
    Tim Arheit, Mar 4, 2005
    #4
  5. matt_1ca

    matt_1ca Guest

    Hello Laurie,

    Thank you for your reply.

    I will keep all your suggestions in mind.

    Gratefully,
    Matt
     
    matt_1ca, Mar 5, 2005
    #5
  6. matt_1ca

    rwilkins Guest

    Requirements:
    1. You must specify line numbers for each line of code.
    2. Use the 'Erl' function to return what line caused the error.

    Public Sub ErrTest()
    On Error GoTo Err_Handler

    1 ThisDrawing.SelectionSets.Add ("Test")

    2 ThisDrawing.SelectionSets.Add ("Test")


    Err_Handler:
    MsgBox "Error in ErrTest" & vbCr & _
    "Description: " & Err.Description & vbCr & _
    "Line number: " & Erl
    End Sub
     
    rwilkins, Mar 7, 2005
    #6
  7. matt_1ca

    fantum Guest

    I have mentioned this before but you can embed debug symbols in your executable and debug it from visual studio including break points, stepped execution, and variable insepection.
     
    fantum, Mar 8, 2005
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.