Solved

Get Procedure or Function Name within Itself

Posted on 2002-05-14
13
143 Views
Last Modified: 2010-05-02
Hi,
Is there a function that returns the name of a sub or function within the sub or function. Eg

Private Sub cmdReadINI_Click()

Have a function that would return cmdReadINI as a string
   

End Sub

I know that I can get the name of the current module by using Me.Name.

Thanks,
d
0
Comment
Question by:dingo11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 4

Expert Comment

by:RichW
ID: 7009330
There's really no way to do this in VB.  You can find the function from the calling statement in the VB IDE, but this is because Visual Basic stores this information for the IDE only.

You could try to examine the call stack but I'm not sure if this would be useful either.

Depending on what you want to do, you could set a global variable equal to the name of the function inside the function and use it later on, but I'm not sure how useful that would be either.

Why do you need this?

Sorry.

RichW
0
 

Author Comment

by:dingo11
ID: 7009377
rich,
I'd like to keep track of the sub or fuction that generated an error, and I thought I could save some time. if a function similar to me.name existed.

D
0
 
LVL 4

Expert Comment

by:RichW
ID: 7009432
I don't believe there is one.  Sorry.

You can do this in your error handling.

I always place the function/sub name in the error handler's msgbox.

Rich
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:ventond
ID: 7009434
Since you have to have code in each procedure to handle errors. Why not just use a literal in each procedure that you need it in?
0
 

Author Comment

by:dingo11
ID: 7009466
v,
What's the chances on an example of a using a literal please.

rich,
That sounds interesting, an example place the function/sub name in the error handler's msgbox please.
d
0
 
LVL 4

Accepted Solution

by:
RichW earned 75 total points
ID: 7009487
Public Sub Whatever()

On Error GoTo err_Whatever
Dim x As Integer

x = "Yo!"

Exit Sub
err_Whatever:
MsgBox Err.Number & " " & Err.Description & " in Sub Whatever()"
End Sub
0
 

Author Comment

by:dingo11
ID: 7009531
guys,
I came in at the end of a project that has limited error checking. Just trying to cut out the tedious stuff.I guess I'll have to use me.name, at least that will pin down the module.
d
0
 
LVL 4

Expert Comment

by:RichW
ID: 7009641
Sorry dingo11, but there really is no other to do this in VB.  The error handler suggestion I made works for me when debugging and app.

I use the same line in all the error handles and then replace it with a more appropriate message when sending out to users.



0
 
LVL 1

Expert Comment

by:carpediem
ID: 7009675
There are some pretty good third-party tools out there that will automatically insert pretty good code handling (including the module it occured in) automatically.  Some of these can cost a little bit, but if it is a big project it can litterally mean the difference between spending weeks adding and testing the code or just telling the utility how you want the error handling to work and clicking the go button.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7009725
Yes, you could get the module name if it is a form. There is no Me keyword for code modules.
0
 
LVL 2

Expert Comment

by:ventond
ID: 7010356
RichW's code was pretty much what I was alluding to.
0
 

Author Comment

by:dingo11
ID: 7010743
Hi,
I have a wicked free add on -> tool bar that handles msgboxes, error checking and a wack of other things. I found it through a person here at the experts-exchange, its called MZ-Tools 3.0.

richie,
thanks for that tid bit, my programming career has been a mixture of work -> long period unemployed -> work -> long period unemployed and happily enough back to work. Each time having to relearn a number of basics.

d
0
 

Author Comment

by:dingo11
ID: 7010746
Rich,
Thanks again. Have a great day programming,
d
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question