R
Rhino
Is there any way that a macro can determine its own name while it's
executing?
I am trying to polish some error handling logic. Every time I encounter
something that should be written to my error log, I'd like to pass the name
of the procedure which encountered the error to the procedure that will
write to the log.
For example, if I am executing a procedure named storeDataFormat and it
encounters an error, I'd like to have code like this:
msg = "Data format is incorrect."
log (msg, whatIsMyName)
Then, the 'log' macro will look like this:
sub log(message As String, macroName As String)
write #logFileNumber, Now & " - " & macroName & " - " & message
end sub
In the code above, 'whatIsMyName' is just a placeholder for a real VBA
function that obtains the name of the currently-executing macro,
storeDataFormat in this example. Is there any _real_ function in VBA that
will do that?
I realize that I could just code a String that has the desired information,
e.g. 'log (msg, "storeDataFormat"), but it would be more elegant to have VBA
figure it out. That way, if I ever changed the name of the procedure, I
wouldn't have to remember to change the string that contained the macro
name.
---
Alternatively, is there any way to generate something akin to a Java
stackTrace at will?
In a Java program, I can ask for a stackTrace any time and it will display
all of the procedures that are running. Therefore, if I'm in the log
procedure, which was invoked from the storeDataFormat procedure which was in
turn invoked from the createResumeFromFile procedure, the stackTrace would
show me each of those procedure names as well as telling me which line I was
executing in each of them.
If I could get something like a stackTrace, I wouldn't need a function that
could tell me the name of the currently executing macro.
executing?
I am trying to polish some error handling logic. Every time I encounter
something that should be written to my error log, I'd like to pass the name
of the procedure which encountered the error to the procedure that will
write to the log.
For example, if I am executing a procedure named storeDataFormat and it
encounters an error, I'd like to have code like this:
msg = "Data format is incorrect."
log (msg, whatIsMyName)
Then, the 'log' macro will look like this:
sub log(message As String, macroName As String)
write #logFileNumber, Now & " - " & macroName & " - " & message
end sub
In the code above, 'whatIsMyName' is just a placeholder for a real VBA
function that obtains the name of the currently-executing macro,
storeDataFormat in this example. Is there any _real_ function in VBA that
will do that?
I realize that I could just code a String that has the desired information,
e.g. 'log (msg, "storeDataFormat"), but it would be more elegant to have VBA
figure it out. That way, if I ever changed the name of the procedure, I
wouldn't have to remember to change the string that contained the macro
name.
---
Alternatively, is there any way to generate something akin to a Java
stackTrace at will?
In a Java program, I can ask for a stackTrace any time and it will display
all of the procedures that are running. Therefore, if I'm in the log
procedure, which was invoked from the storeDataFormat procedure which was in
turn invoked from the createResumeFromFile procedure, the stackTrace would
show me each of those procedure names as well as telling me which line I was
executing in each of them.
If I could get something like a stackTrace, I wouldn't need a function that
could tell me the name of the currently executing macro.