Home All Groups Group Topic Archive Search About

Getting the current procedure name?

Author
10 Nov 2006 8:11 PM
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

Author
10 Nov 2006 7:28 PM
rowe_newsgroups
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/microsoft.public.dotnet.languages.vb/browse_thread/thread/8d8ec2d0f77e7f88/c23a0015ecf89e47?lnk=gst&q=current+method+name&rnum=2#c23a0015ecf89e47

Thanks,

Seth Rowe


Ronchese wrote:
Show quoteHide quote
> 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--
Author
10 Nov 2006 9:28 PM
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.



"rowe_newsgroups" <rowe_em***@yahoo.com> escreveu na mensagem
news:1163186891.563352.189010@b28g2000cwb.googlegroups.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/microsoft.public.dotnet.languages.vb/browse_t
hread/thread/8d8ec2d0f77e7f88/c23a0015ecf89e47?lnk=gst&q=current+method+name
&rnum=2#c23a0015ecf89e47
Show quoteHide quote
>
> 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;
Show quoteHide quote
> > &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--
>
Author
10 Nov 2006 7:52 PM
MikeMc
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.

Show quoteHide quote
"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
Author
10 Nov 2006 9:23 PM
Ronchese
That works fine for me. Thanks!



Show quoteHide quote
"MikeMc" <Mik***@discussions.microsoft.com> escreveu na mensagem
news:D131F3C0-175C-4DFE-96B1-E95D5879EE90@microsoft.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
Author
14 Nov 2006 3:01 PM
Brian Tkatch
Ronchese wrote:
Show quoteHide quote
> 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.
Author
15 Nov 2006 12:39 PM
Phill W.
Ronchese wrote:

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

System.Reflection.MethodBase.GetCurrentMethod().Name

HTH,
    Phill  W.