Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Retrieving the procedure name at run time

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
jones_r
Asked:
jones_r
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
Mark_FreeSoftwareCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gafoorgkCommented:
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
 
Naveen SwamyCommented:
hope the above links helps you
0
 
jones_rAuthor Commented:
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
 
Mark_FreeSoftwareCommented:
>>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

Hire Technology Freelancers with Gigs

Work with 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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now