Logging the current sub's name....


    I'm sure this comes up all the time. I would like to log errors / information and report the name of the sub / function from which they come. Is there any way to do this implicitely? Basically, I need a call which returns the current sub's name. Can it be done?

Cheers, Nik.
Who is Participating?
wsh2Connect With a Mentor Commented:
At run time.. only with Hard coding.. <sigh>.

There is no built-in functionality for this.

The way to do this is to declare a global variable and set its value at the beginning of each procedure.

Ture Magnusson
Karlstad, Sweden
Hi Nik
At the start of application open the log file using Open statement .

In each critical procedure<u want log>, use On Error goto ErrHandler

In err handler Use Print # method to log the error along with time etc:

'say number is 1 for LogFile
Exit Function
Print #1, Now & ": Function GetValue:" _
& Err.Descripotion

Hope it helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.