• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 82
  • Last Modified:

How to incorporate an error traping routing to existing code in VB6

We have an old large code in VB6 and are getting error that can't seem to pinpoint where they are.  What's the best way to include some sort of error-trapping routing so it can capture the error and display any additional information we would like.
0
rayluvs
Asked:
rayluvs
  • 6
  • 5
1 Solution
 
Martin LissRetired ProgrammerCommented:
Private Sub Form_Load()

    On Error GoTo ErrorRoutine

    'code here

    Exit Sub

ErrorRoutine:

    'DisplayError "Form_Load"
    'OR
    MsgBox Err.Number & " " & Err.Description
End Sub

Open in new window

Also see my article on debugging.
0
 
Martin LissRetired ProgrammerCommented:
Also MsgBox erl will give you the line number if the procedure has line numbers.
0
 
rayluvsAuthor Commented:
Thanx!

Is there a way to display the line or section with module the error occurred?
0
Industry Leaders: 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!

 
rayluvsAuthor Commented:
if no line numbers? any advice?
0
 
rayluvsAuthor Commented:
We noticed that with Err.Number and Err.Description it displays the same error as not trapping it.  How can we make the error trapping more useful, maybe where the error came from or something with some sort of direction.
0
 
Martin LissRetired ProgrammerCommented:
If you knew which procedure was generating the error you could add line numbers to it and problem solved, but determining the procedure can be a problem.

One way to do that is to place a few Debug.Print lines containing the name of the procedure at the start of a few likely procedures, and if you don't see the procedure in the Immediate window you know it didn't get that far and you can add more Debug.Print statements farther back, etc. That can be tedious however but see my Automatic Insertion of Procedure Names add-in for an easy way.
0
 
Martin LissRetired ProgrammerCommented:
We noticed that with Err.Number and Err.Description it displays the same error as not trapping it.  How can we make the error trapping more useful, maybe where the error came from or something with some sort of direction.
Again, you'd need to be in the offending procedure to do anything useful. If you were in the procedure you could put a breakpoint in the first line of the ErrorRoutine, add a temporary Resume statement following it, and press F8 to get to the offending line. Read my debugging article to get more ideas.
0
 
rayluvsAuthor Commented:
Thanx!  We went over your article but it's more directed to debug while in design, our concern is in the EXE that is produce by the "Make" option.  Any advice in this area for debugging?

Note:
With your example, we setup variables within the suspected procedure to see if its there.  

For example:

We created a variable called errorLocation and use it to capture sections of the routine or right before each area where we "think" there is a problem

errorLocation="Right before 'For X = 0 To'
VB line - For X = 0 To UBound(varsData)

Open in new window


or

errLocation = "Right before 'Select Case VarsType"
VB line - Select Case VarsType

Open in new window

or

errLocation = "Right before 'conn.Open"
VB line - cnn.Open "Provider=SQLOLEDB; " & _

Open in new window


Then when the error is capture in 'ErrorRoutine:' we place the line to be display:

ErrorRoutine:
  MsgBox "Error Number:" & Err.Number & vbCrLf _
  & Err.Description & vbCrLf & "Area where its was stopped = " & errLocation 

Open in new window


Something like that

any advice?
0
 
Martin LissRetired ProgrammerCommented:
You can't debug a running exe. Do you have the code? If so then zip up the project including any databases, etcetera and I'll try to find the error for you.

What is the error that you are getting?
0
 
rayluvsAuthor Commented:
Thanx, that's very nice of you!  But, found the error the first time you gave us the routine & solved it.  Just wanted to know if there any strategy for debugging a sunning exe.

Anyways, if you do have some sort of technique or steps for debugging a running exe, glad to hear of it.

Thanx!
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help. The only way to do any kind of debugging in a running exe is to use the method I described in post ID: 41869350 but using Msgboxes instead of Debug.Print statements.

If you expand the “Full Biography” section of my profile you'll find links to some other articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
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.

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