Programatically retrieving name of a sub/Function?

  • Thread starter Thread starter Rick Derthick
  • Start date Start date
R

Rick Derthick

Hello,

I'm adding a logging capability to error handler routines for
troubleshooting (using vb.net) and had just recently come across a way to
programatically determine the name of the subroutine or function.

For example...

Private Sub SomeRoutine()
Dim strRoutineName

strRoutineName = ??????? 'where strRoutineName would be equal to
"SomeRoutine"
End Sub

Can someone provide an example of how to accomplish this? I'm trying to
keep the error handler code uniform thoughout the project and therefore
would rather not hard code the name of the routine into each error handler.

Thanks
Rick
 
Try This,


MethodBase.GetCurrentMethod().Name form the System.Reflection namespace


Regards - OHM
 
* "Rick Derthick said:
I'm adding a logging capability to error handler routines for
troubleshooting (using vb.net) and had just recently come across a way to
programatically determine the name of the subroutine or function.

For example...

Private Sub SomeRoutine()
Dim strRoutineName

strRoutineName = ??????? 'where strRoutineName would be equal to
"SomeRoutine"
End Sub

\\\
MsgBox(System.Reflection.MethodBase.GetCurrentMethod().Name)
///
 
Back
Top