Results 1 to 6 of 6

Thread: Get last line of code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    SLOVENIA, Europe
    Posts
    110

    Question

    Is it possible to view in run time the program line which result error. Something like this:

    Code:
    Private Sub Command1_Click()
    On Error GoTo err_handler
     
     Open "c:\data\some_text.txt" For Input As #1
     'that file doesn't exists, so program jump to err_handler
    
    err_handler:
     If Err.Number = 76 Then
        MsgBox "Error: " & Err.Number & " " & Err.Description
     End If
      
    End Sub
    This code generates error. I want to see

    Open "c:\data\some_text.txt" For Input As #1

    in my msgbox or write it in log file.

    Or is there some other way?

    Why I need this? I wrote program for another company which distribute it to their customers. But unfortunately they are not computers programmers like me (even ordinary computers users knows more than employees in this company) and I have hard time to understand them if there is an error in program.

    Program is quite complex and many conditions must be meet for program to work properly (user must prepare those conditions) so I don’t wanna discus about error handling!

    I just wanna the last line of code in log file (code that generates error).

    Thnx for your help!

    Ermin
    Ermin Gutenberger

    VB.NET 2010

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Not directly but you can retrieve the error line number using erl

    Code:
    Private Sub Command1_Click()
    On Error GoTo err_handler
     
    10: Open "c:\data\some_text.txt" For Input As #1
     'that file doesn't exists, so program jump to err_handler
    
    err_handler:
     If Err.Number = 76 Then
        MsgBox "Error line number: " & ERL
     End If
      
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Unhappy Auto insert line number.

    Hi! Kedaman, It is possible that VB itself insert all the reference line number into the source code, so that when an unexpected error occur we can call the Erl object to return the line number that encounter error.

    Else, it'll be very painful for those wish to use this object yet does not make sense for the Erl object itself.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    SLOVENIA, Europe
    Posts
    110
    Thanks for your answer. Now my program looks like basic program on old Commodore computer, but it works.

    If U have any other suggestion, fell fre to replay!

    Ermin
    Ermin Gutenberger

    VB.NET 2010

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hehe, the line number sure looks ugly but it doesn't mean theres any loss in performance

    I'm not sure but i think ERL is part of Err object, it doesn't appear anywhere at all not even object browser, i just happened to discover it since it existed in qbasic.

    Nope, Vb doesn't put these line numbers by it self, either you have to do it or, make an add-in that does it for you.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    Em... do you wrote any VB Add-in before? If yes, Can share some of your knowledge in writing VB Add-in?

Posting Permissions

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



Click Here to Expand Forum to Full Width