-
August 6th, 2004, 06:32 AM
#1
Getting the Line Number on a VB error
Hi All,
Well my project has gone out to the public, 5 have sold, and already problems, I have tried to trap the errors, and its all fine and well getting the error number and description, but getting when its doing it out of the user is a nightmare.
surely there must be a way in Visual Basic you can get it to return the Line number the error is happening on ?
Does anybody know how to achieve this ?
Please, please, please, please help.....
-
August 6th, 2004, 06:39 AM
#2
Code:
private sub yoursub()
On error goto ErrHandler
dim sName as string
dim iAge as integer
1: sName ="mario"
2: iAge =sname
3: msgbox "No mistake ? Or did you see a line number?"
ErrHandler:
msgbox err.description & vbcrlf & " Line of error:" & Erl
resume 3
end sub
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 6th, 2004, 06:40 AM
#3
(note: you can also skip the ":" after the number...)
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 6th, 2004, 06:50 AM
#4
Cheers Cimperiali
I had found that but just kept getting line 0
Do I have to type all the line numbers in down the left hand side, or can they be put in automatically ?
Much appreciated
Ken
-
August 6th, 2004, 07:28 AM
#5
Fantastic!
Sure wish I knew about this earlier...
Yes, you do need line numbers for every line, at least those which you might suspect are causing problems. This is because the compiled exe doesn't consist of lines of code, so it really can't tell you unless there is something that becomes part of the compiled version.
I just did a simple test:
Code:
Private Sub Command1_Click()
Dim A$, I&
On Error Resume Next
5 A = "hello"
ThisSpot: I = A
If Err Then Debug.Print Erl
End Sub
The number returned is 5, even though that line didn't cause an error. Seems it will return the last line number before the error occures.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
August 6th, 2004, 11:00 AM
#6
The ERL will only return the last line number it encountered, so it means you have to drop it into places where you think there may be an error.
Another thing I found useful was to set up conditional debugging. In my program I have code that says
Code:
IF COMMAND$ = "D3BUG" THEN
MSGBOX .....
ENDIF
I can set up a short cut to the exe which contains D3BUG after the application name. I misspell it, so that people don't generally know its there.
HTH
JP
Please remember to rate all postings.
-
August 6th, 2004, 11:05 AM
#7
As we are into it...write to a log file.
Another useful tecnique is to open a (txt) file for append
and write some infos in it
(like "Stepped in this sub", "found this value", "raised this error"...)
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|