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

Return Sub Name

Status
Not open for further replies.
Apr 9, 2002
102
US
Is there a way to return the sub name that you are currently in? I am going to use this for debugging errors. Any help you can provide is much appreciated. Thanks.

Marrow
 
Not that I am aware of. But there are other means of accomplishing the feat, by cheating.


' At the start
ShowSub("MySub", 1)

' On exit
ShowSub("MySub", -1)


Public Sub ShowSub(SubName As String, Increment As Integer)

Static strSpaces As String
Dim strSubLine As String

If Increment = 1 Then
strSpaces = strSpaces
strSubLine = strSpaces & "Entering "
ElseIf Increment = -1 Then
strSpaces = Left$(strSpaces, Len(strSpaces) - 1)
strSubLine = strSpaces & "Leaving "
End If
Debug.Print strSubLine & SubName

End Sub
Call ShowSub("MySub", -1)
Entering MySub
Entering MySub
Entering MySub
Entering MySub
Entering MySub
Leaving MySub
Leaving MySub
Leaving MySub
Leaving MySub ----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top