?
Solved

Get Procedure or Function Name within Itself

Posted on 2002-05-14
13
Medium Priority
?
147 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 300 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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