Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to a function name within the function

Status
Not open for further replies.

webuser

MIS
Jun 1, 2001
202
US
Is there any way to get the value of a function from within that function. Here is what I mean:

Given the function:

Public Function AddTwoNumbers(x as integer, y as integer)

AddTwoNumbers = x + y

End Function

--Can I do this in any way:
MsgBox "My function name is " & FunctionName

--Also, can I find out what function or procedure called the function? So I would do something like this:
MsgBox "My function called by " & CallingFunctionName

I hope I explained myself. Thanks in advance.






 
There is no property or anything that tells you the name of the sub or function you're running, which is a bit of a drag. This means that there's generic way of telling the user the name of the procedure--you'll have to hard code it.

The same is true of calling procedures. To know where it was called from, make another parameter, strCallingProcedure, or something like that, and refer to that.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Thanks. That's kind of what I figured...But I was hoping against all odds...Do you know if other languages (.net, C++ or any others) have such a mechanism built in?
 
Perl has a function named "caller" that returns info
like this. "(caller(0))[3]" returns the name of the
subroutine you're currently in, in the format
"package::sub", like "main::mysub". If you don't want
the package name, it's fairly easy to remove it.

I won't go on about this too much here, since this isn't
the Perl forum. If you're interested you can check it
out.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top