By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

is there a way to do this

P: n/a
ari
hey all,

Given a simple subroutine/function is there a way to find out who the caller
is? (what line of code called it)

thanks,
ari
Feb 14 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
=?Utf-8?B?YXJp?= <ar*@discussions.microsoft.com> wrote in
news:8B**********************************@microsof t.com:
hey all,

Given a simple subroutine/function is there a way to find out who the
caller is? (what line of code called it)

thanks,
ari


*Confessor nods*

Simply define it with arguments... the little things you find in the
parentheses of the "event" subs the development environment makes for you.

You'll want to ByVal or ByRef (See which one works; I often forget the
difference between the two) a variable as a string...

And whenever you call the sub, put between the parentheses some identifying
value, like "From Sub Main."

Or at least, that's how I recall doing it; it's been a few months since my
last project that required it.
Feb 14 '06 #2

P: n/a
CMM
Dim trace As New System.Diagnostics.StackTrace

If trace.FrameCount > 1 Then
Dim frame As System.Diagnostics.StackFrame = trace.GetFrame(1)

MsgBox(frame.GetMethod().Name)
End If

--
-C. Moya
www.cmoya.com
Feb 14 '06 #3

P: n/a
You'll want to check the stack trace.

http://www.experts-exchange.com/Prog..._20620588.html

Feb 14 '06 #4

P: n/a
You can use "System.Reflection.MethodBase.GetCurrentMethod.Nam e" to
know the methods and functions names in runtime

Feb 14 '06 #5

P: n/a
ari
thanks everyone for the great feedback.

"ari" wrote:
hey all,

Given a simple subroutine/function is there a way to find out who the caller
is? (what line of code called it)

thanks,
ari

Feb 24 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.