Getting the current procedure name?

G

Guest

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.
 
R

Ronchese

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
 
R

Ronchese

That works fine for me. Thanks!



MikeMc said:
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.
 
R

Ronchese

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.
 
B

Brian Tkatch

Ronchese said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top