Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What function are you in?

Status
Not open for further replies.

Jengo

Programmer
Apr 17, 2000
100
US
Does anyone know how to display what function you are in? For example if you are in a function and an error occurs, is there a way for you to get what function the error occured in?
 
I always just set the title of the message box in the error handling routine to show the name of the function or sub, or to display some other element that might help me diagnose by telephone when a user calls. Something like:

function fnBlah()
on error goto errFnBlah

brilliant VBA codes goes here

exit function
errFnBlah:
beep
MsgBox Err.Description,,"Function: fnBlah"
end function

This what you're talking about?

-Terry




 
I was wondering if there was a function freindly way of find out. If there was some way that I could pass the function name. I know that I can pass what function it is through a string, but I was wondering if there was a feature or way that it could work for more than one function?
 
Jengo,

This is often/usually done by declaring a global string variable in a public module (e.g. Global MyModuleName as String) and placing a line of code in EVERY procedure to which places the procedure name in that variable (e.g. MyModuleName = "ThisProcedure" where "ThisProcedure " is the actual name of the procedure.

In your error trapping functions, you can use the value of "MyModuleName" to say what procedure you are in.

Variations on this theme exist, but this is the most common.
One not-to-unreasonable variation is to have each module 'print' the name to a text file at each entry. This provides a 'running history' of the process, and may be useful in tracing an application. Also, additional information may be sent to the log file, including hte value of arguments on entry. To use this approach, you need to also set a flag to tell the system to log/not log activity, as the log can slow your app down -A LOT- and use up a lot of disc space in a production operation.



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Jengo,

This is often/usually done by declaring a global string variable in a public module (e.g. Global MyModuleName as String) and placing a line of code in EVERY procedure to which places the procedure name in that variable (e.g. MyModuleName = "ThisProcedure" where "ThisProcedure " is the actual name of the procedure.

In your error trapping functions, you can use the value of "MyModuleName" to say what procedure you are in.

Variations on this theme exist, but this is the most common.
One not-to-unreasonable variation is to have each module 'print' the name to a text file at each entry. This provides a 'running history' of the process, and may be useful in tracing an application. Also, additional information may be sent to the log file, including hte value of arguments on entry. To use this approach, you need to also set a flag to tell the system to log/not log activity, as the log can slow your app down -A LOT- and use up a lot of disc space in a production operation.



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
The logic behind not having such a feature is that at runtime the function name is really converted to an address. Because VBA is interpreted, it would have been possible for Microsoft to include this feature - but you aren't supposed to think of the code this way. Rob Marriott
rob@career-connections.net
 
Try right click the error or variable, definition, it will point where it is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top