Solved

Get Procedure or Function Name within Itself

Posted on 2002-05-14
13
137 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now