Solved

Retrieving the procedure name at run time

Posted on 2006-06-27
8
240 Views
Last Modified: 2010-04-07
I am writing a global procedure that send an email to the sys admin when an erro occurs in the app. Besides the error info, I would like to include in the email message: the Form name  (me.name), the procedure name (???) and the actual line of code that generated the error (or the line number???).


the procedure name :
     Is there a way to retrieve the proc name turning runtime, without having it hard-coded in the call statement?

     current syntax:
       Call ErrorNotify err, "hello@world.com", Me.Name & ".Form_Load"

     would like it to be something like:
       Call ErrorNotify err, "hello@world.com", Me.Name & "." & < proc name >

the line that caused the error:
      Is there a way to retrieve the line of code that caused the error?

thanks,

R
0
Comment
Question by:jones_r
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16996616
in vb6, there is no automatic way to get that information. only from vb.net on you have the call stack information available from code.
0
 
LVL 9

Expert Comment

by:dancebert
ID: 16996718
0
 
LVL 13

Assisted Solution

by:Mark_FreeSoftware
Mark_FreeSoftware earned 200 total points
ID: 16997136
the name of the procedure is not possible (without hardcoding it)


the line is possible!

you have to assign numbers to lines,
and then to find the line, you ahve to use the (undocumented) function erl

example:

private sub Form_load()
dim i as long
on error goto error_1
1  msgbox "Hello"
2 i = inputbox("what value?")
3 i = i + 5
4  i = 5/0
exit sub
error_1:
msgbox "The error occured on line " & erl
end sub

this will find an error on line 4
if you enter a string, it will find an error on line 2
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Accepted Solution

by:
gafoorgk earned 300 total points
ID: 16998614
well, it's true that you cannot retrieve the procedure name in normal way. but it can be done using "Microsoft Visual Basic 6.0 Extensibility" library. i don't recommend using that before u know a bit about extending vb functionality.

instead use the nice free add-in tool MZ-Tools v3.0 for VB6. goto http://www.mztools.com/index.htm for that
0
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 17000564
0
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 17000581
hope the above links helps you
0
 

Author Comment

by:jones_r
ID: 17004024
Gafoorgk  - the add-in was able to auto assign the line numbers and has a function to auto add the proc name in the error statement.  Overall, a very cool tool.

Mark - the erl function is a great find!  Thanks!  (though I would have hated to have had to manually enter all the line numbers for this to have worked)

Was not sure what the etiquette is when both of your answers helped me to achieve the final solution -- I marked the more helpful one as the accepted answer and split the points 300 - 200 (???)

The error statement in the proc is auto populated by the mz tools add-in 'create error statement' function

Form_Load_Error:
230        If err.Number > 0 Then
240          Call err_emailHandler(err, "Form_Load")
               'Resume Next
250        End If
End Sub

This proc gathers the error, line number, and form name + proc name and sends it to the global email proc (which generates the email to the admin)

Private Sub err_emailHandler(err As ErrObject, ProcName As String)
10            ErrorNotify err, Erl, Me.Name & "." & ProcName
End Sub

Again -- thanks!!

R
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17004277
>>Was not sure what the etiquette is when both of your answers helped me to achieve the final solution -- I marked the more helpful one as the accepted answer and split the points 300 - 200 (???)

as far as i know, that's the function of the split option!


(i like to give points that way too)



>>The error statement in the proc is auto populated by the mz tools add-in 'create error statement' function
//extra (free) tip:
did you know that you can edit this error statement?
click in tools (in the menu)
then mz-tools then options

then click on the tab error handler



thanks for the points, and happy coding!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

815 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

10 Experts available now in Live!

Get 1:1 Help Now