Solved

Get Procedure or Function Name within Itself

Posted on 2002-05-14
13
138 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 50
Reading the Contents of a Directory In Access VBA 5 58
Add and format columns in vb6 7 42
Visual Studio 2005 text editor 10 33
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now