i had to do this once to work out a very elusive bug. I had to manually assign each
line of code a unique line number, then use the Erl system variable (not documented
anywhere) to get the exact line number that caused the error. This has saved my
butt a couple of times, but i dont recommend it for anything other than an absolute
last resort.
here's an example:
Public Sub DoSomething()
Dim x as integer
dim y as integer
dim s as string
on error goto handler
1 x = 1
2 y = 5
3 s = "some text"
4 x = x + y
5 x = s
exit sub
handler:
msgbox "error on line " & erl
end sub
--- Yoel Pedersen <y.pedersen@g...> wrote:
> Hi Toby,
>
> I don't know any way to assign each line in VB a number - I've never had
> to use this technique. Using line numbers belongs to the old QBasic - in
> modern Visual Basic it is normally used to assign some few lines a label.
> Instead of referring to a line number in GoTo statements, you just refer
> to the line label. Example:
>
> Private Sub Example()
>
> On Error GoTo Errorhandler 'Tell where to go in case of error
>
> blahblahbla - the code for some procedure here
>
> blabhblah...the end of the procedure code
>
> Exit Sub
>
> Errorhandler: 'The line label
>
> Select Case Err.Number
> Case 53
> MsgBox "File not found"
> Case Else
> MsgBox "An error has occurred"
> End Select
>
> End Sub
>
> In this example I use the line label as an error handler to go to in case
> of an error. This simplifies the code instead of just referring to a line
> number.
>
> Hope it helps,
>
> Sincerely Yoel Pedersen
>
----------------------------
John Pirkey
MCSD
John@S...
http://www.stlvbug.org