Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Retrieving the procedure name at run time

Posted on 2006-06-27
8
Medium Priority
?
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 143

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 13

Assisted Solution

by:Mark_FreeSoftware
Mark_FreeSoftware earned 800 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Accepted Solution

by:
gafoorgk earned 1200 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: 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Suggested Courses

721 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