Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Debug

Posted on 1998-06-01
6
Medium Priority
?
139 Views
Last Modified: 2013-11-25
I have problem using On Error statement
I have 2 method:
Public Sub MethodA()
      :
      :
      On Error Resume Next
      :
      Call MethodB
      :
End Sub

Private sub MethodB()
      :
End sub

The on error statement also triggered in MethodB. How to stop that?
0
Comment
Question by:Cruiser
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
yowkee earned 200 total points
ID: 1462273
 If you didn't put any "On Error" statement in MethodB, it would just follow the error handler of caller function. That's why the on error resume next still make sense in MethodB.

  Just put the Error Handler for MethodB, then it won't follow error handler of MethodA.

Public Sub MethodA()
:
On Error Resume Next
:
Call MethodB
:
End Sub

Private sub MethodB()
On Error GoTo ErrHandler
:
Exit Sub
ErrHandler:
:
:
End sub

0
 

Author Comment

by:Cruiser
ID: 1462274
let said I do not want any error handling in method B, how to do that?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462275
Cruiser,
 
  If you don't want any error handling in MethodB, just disable the error handler in MethodA before it call MethodB. But then any error in MethodB will handled by VB and may come out some unfriendly message to user.

Public Sub MethodA()
:
On Error Resume Next
:
On Error Goto 0  ' Disable error handler in this procedure
Call MethodB
On Error Resume Next  
:
End Sub


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Cruiser
ID: 1462276
Thanks
One last Q, what is the 'range' of a On Error statement?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1462277
This is what stated in VB Help file:

---
On Error GoTo line
       Enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs.

On Error Resume Next      
        Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.
On Error GoTo 0      
        Disables any enabled error handler in the current procedure.

Remarks

If you don't use an On Error statement, any run-time error that occurs is fatal; that is, an error message is displayed and execution stops.
An "enabled" error handler is one that is turned on by an On Error statement; an "active" error handler is an enabled handler that is in the process of handling an error. If an error occurs while an error handler is active (between the occurrence of the error and a Resume, Exit Sub, Exit Function, or Exit Property statement), the current procedure's error handler can't handle the error. Control returns to the calling procedure. If the calling procedure has an enabled error handler, it is activated to handle the error. If the calling procedure's error handler is also active, control passes back through previous calling procedures until an enabled, but inactive, error handler is found. If no inactive, enabled error handler is found, the error is fatal at the point at which it actually occurred.

---
So, it depend which Error Handler is the current active Error Handler and which is enabled. If every procedure got on error statment, the range just within the procedure.
0
 

Author Comment

by:Cruiser
ID: 1462278
Thanks a lot
0

Featured Post

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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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

877 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