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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning the name of current sub or function

Status
Not open for further replies.

ElectricEel

Programmer
Aug 1, 2001
13
US
Is there any way to return the sub or function name that is currently executing? This is to create a general error trap to write the current form and code the error occured and passed to an ErrorClass

Code:
Private Sub MySub()
    On Error Goto ErrHandler
    
    'code

    Exit Sub
ErrHandler:
    Select Case Err.Number
        Case Else
            ErrorClass.ErrorLog Err.Number, Err.Description, Me.Name, "MySub" 
    End Select
End Sub
[\code]

Any suggestions?  

TIA
 
I do the same thing, except I just hard code the name of the sub in there.
 
Thats what I'd like to avoid. I have a couple thousand procedures and functions to update.
 
There are utilities to do it for you, like MZtools. Several threads over the past few weeks have dealt with this same subject.

There is also a way through code to get the sub/function. but it's pretty difficult. Look through this link:


Hope this helps.

Just out of curiosity, does VB.net fix this glaring ommision from VB6?

Robert
 
You can use Reflection in VB.NET to find out the current method. But the easiest way (especially when things go wrong) is to examine the TargetSite property of the Exception object.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top