dingo11
asked on
Get Procedure or Function Name within Itself
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
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
ASKER
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
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
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
You can do this in your error handling.
I always place the function/sub name in the error handler's msgbox.
Rich
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?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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.
I use the same line in all the error handles and then replace it with a more appropriate message when sending out to users.
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.
Yes, you could get the module name if it is a form. There is no Me keyword for code modules.
RichW's code was pretty much what I was alluding to.
ASKER
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
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
ASKER
Rich,
Thanks again. Have a great day programming,
d
Thanks again. Have a great day programming,
d
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