Solved

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

Posted on 2016-11-01
11
48 Views
Last Modified: 2016-11-02
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
Comment
Question by:rayluvs
  • 6
  • 5
11 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41869342
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41869343
Also MsgBox erl will give you the line number if the procedure has line numbers.
0
 

Author Comment

by:rayluvs
ID: 41869344
Thanx!

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

 

Author Comment

by:rayluvs
ID: 41869345
if no line numbers? any advice?
0
 

Author Comment

by:rayluvs
ID: 41869348
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41869350
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41869352
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
 

Author Comment

by:rayluvs
ID: 41869366
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41869431
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
 

Author Comment

by:rayluvs
ID: 41869965
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 41870251
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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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