-
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
-
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
-
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.
-
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
-
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.
-
Em... do you wrote any VB Add-in before? If yes, Can share some of your knowledge in writing VB Add-in?