Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default keep track of last code line before error

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default keep track of last code line before error

Download mz tools excel vba addin and it will add line numbers for you. The
URL is something like www.mztools.com


--
www.alignment-systems.com


"Peter T" wrote:

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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

Hi again,

The other, more important drawback of line numbers is that when you remove
all formatting and comments from
the code to keep the filesize down the line numbers will prevent the leading
tabs being cleared, so the file size
will be a lot bigger. This is apart from the space taken by the linenumbers
themselves.

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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

Actually, this is not that bad if I set the tab width to 1 and then
re-indent with Rob Bovey's Smart Indenter.

RBS

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

The other, more important drawback of line numbers is that when you remove
all formatting and comments from
the code to keep the filesize down the line numbers will prevent the
leading tabs being cleared, so the file size
will be a lot bigger. This is apart from the space taken by the
linenumbers themselves.

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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

Yes, I am using that one.

RBS

"John.Greenan" wrote in message
...
Download mz tools excel vba addin and it will add line numbers for you.
The
URL is something like www.mztools.com


--
www.alignment-systems.com


"Peter T" wrote:

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





  #8   Report Post  
Posted to microsoft.public.excel.programming
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






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default keep track of last code line before error


In practice I only number lines where there is a raesonable chance of an
error. Actually the line itself and the next one.

In my experience good practice avoids most occurances.

Where I am exectuting a line of code that I am expect it to error then
I usually hive off that line to a seperate function or sub-routine. This
makes it quite clear for maintainers of your code that the error trap is
a part of the design rather than a failsafe mechanism.


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=503312

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

Is there a way in MZ Tools to add line numbers for one procedure and
set the starting number other than the default 1 to 10.
The idea is to have the numbering unique throughout the project.
This can be done if I do the whole project, but I don't want that and I even
can't do
that (out of memory).

RBS

"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




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default keep track of last code line before error

Hi Bart,

It doesn't appear possible to change the default options.

Thinking aloud, might be possible to number all lines in your project like
this

mmppxxxxx

mm module number 10-99
pp procedure number 01-99
xxxx line number 00010-99990

Let MZtools do the clever numbering stuff, not unique but first line in each
proc starting with say 10

With each module - increment mm, reset pp
Export text in each module line by line to a text file after doing,
If a line starts with a number then
If it's 10 increment pp and reset xxxxx to "00010"
Else increment xxxxx by 10
Replace the old number with new mmppxxxxx
Re-import

No doubt some things to be careful with, eg next continuation line starts
with a number, increasing already very long lines too much.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Is there a way in MZ Tools to add line numbers for one procedure and
set the starting number other than the default 1 to 10.
The idea is to have the numbering unique throughout the project.
This can be done if I do the whole project, but I don't want that and I

even
can't do
that (out of memory).

RBS

"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




  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default keep track of last code line before error

Hi Peter,

I have done it now like this:
All the Subs that need the line numbers (added with MZ Tools) will now pass
to a central error handler:

The procedure name
The Erl
The Err object, to get the error description and number.
Optional any extra data, such as for example the last SQL query.

This will be written to file and to the clipboard plus there is a msgbox as
well.
As I pass the procedure name the erl's don't have to be unique throughout
the project.
The only thing that now will need some attention is the routine I have to
strip the code of all text that is not
needed, such as comments etc.

RBS


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

It doesn't appear possible to change the default options.

Thinking aloud, might be possible to number all lines in your project like
this

mmppxxxxx

mm module number 10-99
pp procedure number 01-99
xxxx line number 00010-99990

Let MZtools do the clever numbering stuff, not unique but first line in
each
proc starting with say 10

With each module - increment mm, reset pp
Export text in each module line by line to a text file after doing,
If a line starts with a number then
If it's 10 increment pp and reset xxxxx to "00010"
Else increment xxxxx by 10
Replace the old number with new mmppxxxxx
Re-import

No doubt some things to be careful with, eg next continuation line starts
with a number, increasing already very long lines too much.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Is there a way in MZ Tools to add line numbers for one procedure and
set the starting number other than the default 1 to 10.
The idea is to have the numbering unique throughout the project.
This can be done if I do the whole project, but I don't want that and I

even
can't do
that (out of memory).

RBS

"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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to track bottom line results over time for a trend plot? Joe Bailey Excel Discussion (Misc queries) 0 August 17th 06 06:26 AM
Need help - track changes code needs tweaking purpleme3 Excel Programming 0 December 13th 05 11:46 PM
Keeping track of code Eric White[_2_] Excel Programming 4 June 9th 05 09:41 AM
On Error, Capturing current module and actual line of code Paul Martin Excel Programming 4 June 13th 04 06:21 AM
Highlight Track Changes with VBA Code? Garp Excel Programming 1 December 23rd 03 01:32 PM


All times are GMT +1. The time now is 07:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"