Solved

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

Posted on 2016-11-01
11
33 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 45

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 45

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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 45

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 45

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 45

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 45

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now