View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default keep track of last code line before error

Hi Bart,

I understand line numbers start from zero at every new module.


You can label each line with any number you want, numbers don't even need to
be in order. Can use same number-labels in different routines in same
module.

So how would you know what module was run last before the handled error
occured?


Erl on it's own is not going to help, Erl returns the last line label (or 0
if no labels) in the routine that handles the error, not necessarily the
routine in which the error occurred.


Sub Test4()
On Error GoTo err
so = 1
100 MsgBox Test5(so)
200 MsgBox Test5(so)
err:
MsgBox Erl
End Sub

Function Test5(ox) As Long
If ox = 1 Then
On Error GoTo err
End If
10 ox = ox + 1
20 ox = ox / 0

err:
Test5 = Erl
End Function

Regards,
Peter T

PS in your other post - I think "Smart Indenter" is by Stephen Bullen


"RB Smissaert" wrote in message
...
Hi Peter,

I was trying to avoid the line numbers as it makes the code look a bit
messy.
I suppose there is no way round it.
The other thing is how would it handle the different modules?
I understand line numbers start from zero at every new module.
This is now MZ tools does it anyhow.
So how would you know what module was run last before the handled error
occured?
I think in practice this normally will be very obvious, but just in case

it
wasn't.

RBS


"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

Need Line numbers but no need to increment a variable.

Sub test()
On Error GoTo errH

10 x = x + 1
20 x = x + 2
30 x = x / 0
40 x = x + 1
x = x + 1
x = x / 0
50 x = x + 1

Exit Sub
60 x = 10

Exit Sub
errH:
If Erl = 30 Then
Resume Next
Else
MsgBox Erl
GoTo 60
End If
End Sub


Regards,
Peter T


"RB Smissaert" wrote in message
...
Is it possible somehow to keep track of the last line of code that was
run
before a handled error occured without
adding line numbers or without adding a public variable that gets
incremented before every line?
I was thinking of perhaps a class handling VBE events, but I think I

will
need the public variable.
I am not keen to add line numbers.

RBS