Solved

Retrieving the procedure name at run time

Posted on 2006-06-27
8
234 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now