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

Getting the current procedure name?

P: n/a
Hello,

is there any way to get the name of the current running procedure?

For example:

Public Sub Test( )
'do something
'...

'log activity (for example)
objLog.Write(Text := "bla bla bla", _
ProcName := dontKnowWhatIsThis.GetProcName() )
End Sub
Any possibility?

Cesar
Nov 10 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I don't think it anything will return "Public Sub Test" in your
example, but here's a thread that discusses a few methods:

http://groups.google.com/group/micro...3a0015ecf89e47

Thanks,

Seth Rowe
Ronchese wrote:
Hello,

is there any way to get the name of the current running procedure?

For example:

Public Sub Test( )
'do something
'...

'log activity (for example)
objLog.Write(Text := "bla bla bla", _
ProcName := dontKnowWhatIsThis.GetProcName() )
End Sub
Any possibility?

Cesar
------=_NextPart_000_0012_01C704EB.3EC322F0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 1758

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>is there any way to get the name of the current
running procedure?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>For example:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>Public Sub Test( )</FONT></DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp; 'do
something</FONT></DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp;
'...</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp; 'log
activity (for example)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; objLog.Write(Text :=
"bla bla bla", _</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ProcName :=
dontKnowWhatIsThis.GetProcName() )</FONT></DIV>
<DIV><FONT face="Courier New" size=2>End Sub</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any possibility?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Cesar</FONT></DIV></BODY></HTML>

------=_NextPart_000_0012_01C704EB.3EC322F0--
Nov 10 '06 #2

P: n/a
Here is one approach: Get the first frame of the stack trace.

Dim theStackTrace As New StackTrace(True)
Dim theMethod As String =
theStackTrace.GetFrame(0).GetMethod().ToString
MessageBox.Show(theMethod)

Place the code inside a method to see it get and display the method's
signature.

--
Mike McIntyre
http://www.getdotnetcode.com
"Ronchese" wrote:
Hello,

is there any way to get the name of the current running procedure?

For example:

Public Sub Test( )
'do something
'...

'log activity (for example)
objLog.Write(Text := "bla bla bla", _
ProcName := dontKnowWhatIsThis.GetProcName() )
End Sub
Any possibility?

Cesar
Nov 10 '06 #3

P: n/a
That works fine for me. Thanks!

"MikeMc" <Mi****@discussions.microsoft.comescreveu na mensagem
news:D1**********************************@microsof t.com...
Here is one approach: Get the first frame of the stack trace.

Dim theStackTrace As New StackTrace(True)
Dim theMethod As String =
theStackTrace.GetFrame(0).GetMethod().ToString
MessageBox.Show(theMethod)

Place the code inside a method to see it get and display the method's
signature.

--
Mike McIntyre
http://www.getdotnetcode.com
"Ronchese" wrote:
Hello,

is there any way to get the name of the current running procedure?

For example:

Public Sub Test( )
'do something
'...

'log activity (for example)
objLog.Write(Text := "bla bla bla", _
ProcName := dontKnowWhatIsThis.GetProcName() )
End Sub
Any possibility?

Cesar

Nov 10 '06 #4

P: n/a
No problem, I dont need the VB sintax togheter, I just needed the procedure
name.
I gave a look in the thread you wrote, also works good like the code MikeMc
wrote.

Thanks.

"rowe_newsgroups" <ro********@yahoo.comescreveu na mensagem
news:11**********************@b28g2000cwb.googlegr oups.com...
I don't think it anything will return "Public Sub Test" in your
example, but here's a thread that discusses a few methods:

http://groups.google.com/group/micro...es.vb/browse_t
hread/thread/8d8ec2d0f77e7f88/c23a0015ecf89e47?lnk=gst&q=current+method+name
&rnum=2#c23a0015ecf89e47
>
Thanks,

Seth Rowe
Ronchese wrote:
Hello,

is there any way to get the name of the current running procedure?

For example:

Public Sub Test( )
'do something
'...

'log activity (for example)
objLog.Write(Text := "bla bla bla", _
ProcName := dontKnowWhatIsThis.GetProcName() )
End Sub
Any possibility?

Cesar
------=_NextPart_000_0012_01C704EB.3EC322F0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 1758

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>is there any way to get the name of the
current
running procedure?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>For example:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>Public Sub Test( )</FONT></DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp;
'do
something</FONT></DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp;
'...</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp;
'log
activity (for example)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;
objLog.Write(Text :=
"bla bla bla", _</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ProcName :=
dontKnowWhatIsThis.GetProcName() )</FONT></DIV>
<DIV><FONT face="Courier New" size=2>End Sub</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any possibility?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Cesar</FONT></DIV></BODY></HTML>

------=_NextPart_000_0012_01C704EB.3EC322F0--

Nov 10 '06 #5

P: n/a

Ronchese wrote:
Hello,

is there any way to get the name of the current running procedure?

For example:

Public Sub Test( )
'do something
'...

'log activity (for example)
objLog.Write(Text := "bla bla bla", _
ProcName := dontKnowWhatIsThis.GetProcName() )
End Sub
Any possibility?

Cesar
------=_NextPart_000_0012_01C704EB.3EC322F0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 1758

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hello,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>is there any way to get the name of the current
running procedure?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>For example:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" size=2>Public Sub Test( )</FONT></DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp; 'do
something</FONT></DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp;
'...</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#008000 size=2>&nbsp;&nbsp;&nbsp; 'log
activity (for example)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; objLog.Write(Text :=
"bla bla bla", _</FONT></DIV>
<DIV><FONT face="Courier New" size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ProcName :=
dontKnowWhatIsThis.GetProcName() )</FONT></DIV>
<DIV><FONT face="Courier New" size=2>End Sub</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any possibility?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Cesar</FONT></DIV></BODY></HTML>

------=_NextPart_000_0012_01C704EB.3EC322F0--
You may want to look at System.Reflection. IIRC, moduleinfo.

B.

Nov 14 '06 #6

P: n/a
Ronchese wrote:
is there any way to get the name of the current running procedure?
System.Reflection.MethodBase.GetCurrentMethod().Na me

HTH,
Phill W.
Nov 15 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.