Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Obtain Name of Function or Sub

Hi Experts

I would like to include the name of the current function or subroutine in my
error handler output. Is there any property that will provide the name or
context of the current point in the call chain?

Thanks much,

Roger


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Obtain Name of Function or Sub

I create a string variable that stores the name of the subprocedure, location
or any other desired data that I want displayed in the event of an error that
may occur during the running of a subprocedure. Then my On Error procedure
uses a MsgBox that returns the data stored in the variable.

For example:

Sub TryThis()

Dim strErrLocation as string

On Error Goto Err_Handler

strErrLocation = "Start of Subprocedure ABC."

.... other code

strErrLocation = "Allocating Costs portion of the subprocedure."

.... other code

strErrLocation = "Final Clean-Up stage of subprocedure."

.... final clean-up code

Exit Sub

Err_Handler:
MsgBox strErrLocation & vbCrLf & vbCrLf & _
"Err Number: " & Err.Number & " Err Description: " & Err.Description

End Sub

I hope this helps. Good Luck.

"Roger Smith" wrote:

Hi Experts

I would like to include the name of the current function or subroutine in my
error handler output. Is there any property that will provide the name or
context of the current point in the call chain?

Thanks much,

Roger



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Obtain Name of Function or Sub

Thanks Pard

That works so long as the code stays within the context of the current Sub.
But, if you leave the current Sub, say for example with a function call,
then you lose the sErrLocation variable because while you are within the
function call the code is operating in a different context. I was looking
for a way to fetch the name of the function or sub out of one of the
properties - if that information exists.

Cheers,

Rj

"ND Pard" wrote in message
...
I create a string variable that stores the name of the subprocedure,
location
or any other desired data that I want displayed in the event of an error
that
may occur during the running of a subprocedure. Then my On Error
procedure
uses a MsgBox that returns the data stored in the variable.

For example:

Sub TryThis()

Dim strErrLocation as string

On Error Goto Err_Handler

strErrLocation = "Start of Subprocedure ABC."

.... other code

strErrLocation = "Allocating Costs portion of the subprocedure."

.... other code

strErrLocation = "Final Clean-Up stage of subprocedure."

.... final clean-up code

Exit Sub

Err_Handler:
MsgBox strErrLocation & vbCrLf & vbCrLf & _
"Err Number: " & Err.Number & " Err Description: " & Err.Description

End Sub

I hope this helps. Good Luck.

"Roger Smith" wrote:

Hi Experts

I would like to include the name of the current function or subroutine in
my
error handler output. Is there any property that will provide the name or
context of the current point in the call chain?

Thanks much,

Roger





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Obtain Name of Function or Sub

I don't think what you want is possible.
The answer is to do a On Error Goto 0 before execution
moves to the other Sub or Function and then add an
error handler for that other procedure. Then when you come back
in your orginal procedure do another On Error Goto Err_Handler.

RBS


"Roger Smith" wrote in message
...
Thanks Pard

That works so long as the code stays within the context of the current
Sub. But, if you leave the current Sub, say for example with a function
call, then you lose the sErrLocation variable because while you are within
the function call the code is operating in a different context. I was
looking for a way to fetch the name of the function or sub out of one of
the properties - if that information exists.

Cheers,

Rj

"ND Pard" wrote in message
...
I create a string variable that stores the name of the subprocedure,
location
or any other desired data that I want displayed in the event of an error
that
may occur during the running of a subprocedure. Then my On Error
procedure
uses a MsgBox that returns the data stored in the variable.

For example:

Sub TryThis()

Dim strErrLocation as string

On Error Goto Err_Handler

strErrLocation = "Start of Subprocedure ABC."

.... other code

strErrLocation = "Allocating Costs portion of the subprocedure."

.... other code

strErrLocation = "Final Clean-Up stage of subprocedure."

.... final clean-up code

Exit Sub

Err_Handler:
MsgBox strErrLocation & vbCrLf & vbCrLf & _
"Err Number: " & Err.Number & " Err Description: " & Err.Description

End Sub

I hope this helps. Good Luck.

"Roger Smith" wrote:

Hi Experts

I would like to include the name of the current function or subroutine
in my
error handler output. Is there any property that will provide the name
or
context of the current point in the call chain?

Thanks much,

Roger






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Obtain Name of Function or Sub

Just for ideas -

Sub test()
Dim v
On Error GoTo errH
v = "a" ' mismatch
' v = 1 ' div by zero
test2 v
Exit Sub
errH:
MsgBox Err.Description
End Sub

Sub test2(v)
On Error GoTo errH
10
20
30 test3 v
40
Exit Sub
errH:
s = "test2, line:" & Erl & vbCr & Err.Description
Err.Raise 12345, , s
End Sub

Sub test3(v)
On Error GoTo errH
10
20
30 v = v / 0
40
Exit Sub
errH:
s = "test3, line:" & Erl & vbCr & Err.Description
Err.Raise 12345, , s
End Sub

Regards,
Peter T

"Roger Smith" wrote in message
...
Hi Experts

I would like to include the name of the current function or subroutine in

my
error handler output. Is there any property that will provide the name or
context of the current point in the call chain?

Thanks much,

Roger






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Obtain Name of Function or Sub

If that's the only concern, declare the variable Public, then it is available
from any subprocedure or function in the program.


"Roger Smith" wrote:

Thanks Pard

That works so long as the code stays within the context of the current Sub.
But, if you leave the current Sub, say for example with a function call,
then you lose the sErrLocation variable because while you are within the
function call the code is operating in a different context. I was looking
for a way to fetch the name of the function or sub out of one of the
properties - if that information exists.

Cheers,

Rj

"ND Pard" wrote in message
...
I create a string variable that stores the name of the subprocedure,
location
or any other desired data that I want displayed in the event of an error
that
may occur during the running of a subprocedure. Then my On Error
procedure
uses a MsgBox that returns the data stored in the variable.

For example:

Sub TryThis()

Dim strErrLocation as string

On Error Goto Err_Handler

strErrLocation = "Start of Subprocedure ABC."

.... other code

strErrLocation = "Allocating Costs portion of the subprocedure."

.... other code

strErrLocation = "Final Clean-Up stage of subprocedure."

.... final clean-up code

Exit Sub

Err_Handler:
MsgBox strErrLocation & vbCrLf & vbCrLf & _
"Err Number: " & Err.Number & " Err Description: " & Err.Description

End Sub

I hope this helps. Good Luck.

"Roger Smith" wrote:

Hi Experts

I would like to include the name of the current function or subroutine in
my
error handler output. Is there any property that will provide the name or
context of the current point in the call chain?

Thanks much,

Roger






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Obtain Name of Function or Sub

Thanks Peter - that helps... you gave me some new ideas. Much appreciated

Roger

"Peter T" <peter_t@discussions wrote in message
...
Just for ideas -

Sub test()
Dim v
On Error GoTo errH
v = "a" ' mismatch
' v = 1 ' div by zero
test2 v
Exit Sub
errH:
MsgBox Err.Description
End Sub

Sub test2(v)
On Error GoTo errH
10
20
30 test3 v
40
Exit Sub
errH:
s = "test2, line:" & Erl & vbCr & Err.Description
Err.Raise 12345, , s
End Sub

Sub test3(v)
On Error GoTo errH
10
20
30 v = v / 0
40
Exit Sub
errH:
s = "test3, line:" & Erl & vbCr & Err.Description
Err.Raise 12345, , s
End Sub

Regards,
Peter T

"Roger Smith" wrote in message
...
Hi Experts

I would like to include the name of the current function or subroutine in

my
error handler output. Is there any property that will provide the name or
context of the current point in the call chain?

Thanks much,

Roger






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
Need hyperlink function to obtain range name from a cell (contents DW Excel Worksheet Functions 4 January 12th 08 11:07 PM
Function cannot obtain cell values [email protected] Excel Programming 1 December 3rd 07 04:04 AM
How do I obtain the address of a cell using the vlookup function? Spock Excel Worksheet Functions 2 May 16th 05 06:35 PM
Would like to Obtain a Cell Address from a vlookup function CR_2004_04_08 Excel Programming 3 April 9th 04 11:12 AM
How to obtain multiple quantities from an Excel VB function? Tom Kreutz Excel Programming 1 December 10th 03 05:44 PM


All times are GMT +1. The time now is 05:13 PM.

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"