Get name of procedure that is running?

H

headly

Is there a command to get the name of the running procedure?
The reason: My main procedure calls 10 smaller procedures; If any of those
10 procedures throws an error, i want to continue processing and i don't only
want to capture the error code and description, but get the name of the
procedure where the error occured.
 
S

Spreadsheet Solutions

Headly;

Maybe the simplst of things you can do within each of these small procedures
is run an error handler with a messagebox !!!
 
H

headly

The message box stops execution and requires the user to respond; if the
process generates 100 errors I can't have someone babysit it for 30-60
minutes and click OK to each message, I just want to continue processing and
log errors.
 
P

Patrick Molloy

add a new class, call it say clError , then process has an error handler that
(1) creates a new clError object and save it to a collection.
The clError should contain the details - process name, error number, error
message and whatever. the collection should be PUBLIC

at the end of the process, you can interrate through the collection or error
objects to see what happened.

This isn't normal imho. Almost all the investment banks that I work for use
logging extensively to register the processes. This makes it easy (readign
the text file) to see where the process is, and to review any errors
 
C

Charles Williams

I don't know of an automatic way of doing this.
I use a global stack array and line numbers: at the start of each procedure
I add the procedure name into the stack array and and at the end of each
procedure I remove the procedure name. This allows my error handler to
display the call stack, the name of the procedure and the line number. I
also have a debug option in the stack handler that shows the procedure calls
and levels in the Immediate window.

In general this approach seems to work well with a protected XLA.

Charles
___________________________________
The Excel Calculation Site
http://www.decisionmodels.com
 
H

headly

Not clear on what you mean by "logging to register the processes"; Does each
procedure write to a sheet or metadata that it ran?
 
P

Patrick Molloy

you create a text file called something like
LogFile_20091013.txt
you then have a sub that writes to this file eg
Sub WriteLog(text)
LogTextFile.Write text
End Sub

the logtextfile sub would open a textstream object to the file, creating it
if it doesn't exist, and writes the text to it.

The useful thing here is that you can insert the writelog log messages
anywhere in the code...so

WriteLog "Starting main batch..."

WriteLog "Main batch error..."
WriteLog "processbname:" & err.description
 
R

RB Smissaert

Log to a text file like this. strText will hold all the relevant details to
do with the error, such as the name of the procedure,
Err.Description and the error line number, Erl.

Sub LogData(strFilePath As String, strText As String)

Dim hFile As Long

On Error GoTo ERROROUT

hFile = FreeFile
Open strFilePath For Append As #hFile
Print #hFile, strText
Close hFile

ERROROUT:

If hFile > 0 Then
Close hFile
End If

End Sub


RBS
 
J

JP

Unfortunately the source code is not provided completely. You'll need
to read that page and apply the concepts to write most of it. I could
post what I wrote, if anyone wants to see it.

--JP
 
R

RB Smissaert

Yes, thanks, would be interesting.

RBS


Unfortunately the source code is not provided completely. You'll need
to read that page and apply the concepts to write most of it. I could
post what I wrote, if anyone wants to see it.

--JP
 
B

Bernd P

Hello,

I suggest to log some info and to increase or to decrease the amount
of information as far as you need:
http://log4vba.everage.ca/

Advantage: With the right level of detail you will even know (even
long after somebody has run your app) what your users did when.
Disadvantage: Might slow down your app (but - hey, you can switch it
off/on whenever you feel the need).

Regards,
Bernd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top