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

Is there a way to refer to the Function/Sub name?

P: n/a
Is there a way to refer to the name of the function the code is currently
within? I would like to identifiy on a MessageBox the function or sub
containing the message box without hardcoding it in a string, something like
this:

MessageBox.Show("The message to the user." & ControlChars.NewLine & _

"From:" & Me.Name & Function.Name, "Message Title", buttons)


Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Dean Slindee" <sl*****@charter.net> wrote in message
news:fp*******************@fe04.lga...
Is there a way to refer to the name of the function the code is currently
within? I would like to identifiy on a MessageBox the function or sub
containing the message box without hardcoding it in a string, something
like
this:

MessageBox.Show("The message to the user." & ControlChars.NewLine & _

"From:" & Me.Name & Function.Name, "Message Title", buttons)


Dean,

Dim funcName As String = _
System.Reflection.MethodInfo.GetCurrentMethod().Na me

MsgBox( _
"The message to the user." & vbNewLine & _
"From: " & Me.Name & "." & funcName, _
"Message Titel", _
buttons _
)

HTH :)

Mythran

Nov 21 '05 #2

P: n/a
Hi Dean !

You may use the System.Diagnostics.StackTrace class for this :
'***
Option Explicit On

Module Module1

Sub Main(ByVal args As String())

Func1()
Console.WriteLine(New StackTrace().GetFrame(0).GetMethod().Name)

Console.WriteLine()
Console.WriteLine("Press Enter to quit...")
Console.ReadLine()

End Sub

Sub Func1()
Func2()
Console.WriteLine(New StackTrace().GetFrame(0).GetMethod().Name)
End Sub

Sub Func2()
Console.WriteLine(New StackTrace().GetFrame(0).GetMethod().Name)
End Sub

End Module
'***

--
Best Regards
Yanick
"Dean Slindee" <sl*****@charter.net> a écrit dans le message de
news:fp*******************@fe04.lga...
Is there a way to refer to the name of the function the code is currently
within? I would like to identifiy on a MessageBox the function or sub
containing the message box without hardcoding it in a string, something like this:

MessageBox.Show("The message to the user." & ControlChars.NewLine & _

"From:" & Me.Name & Function.Name, "Message Title", buttons)

Nov 21 '05 #3

P: n/a
> System.Reflection.MethodInfo.GetCurrentMethod().Na me

Well... I did learn something today ! <vbg>

--
Best Regards
Yanick
Nov 21 '05 #4

P: n/a

"Zoury" <yanick_lefebvre at hotmail dot com> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
System.Reflection.MethodInfo.GetCurrentMethod().Na me


Well... I did learn something today ! <vbg>

--
Best Regards
Yanick


:) I use Reflection a lot for internal utility routines I have for my
testing applications (Console programs I use to help others in the
newsgroups...) I also had the need to print out the current method name and
didn't like having to type up the name of the method I was currently in for
every method...

Mythran
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.