Solved

Visual basic simple error checking question On error

Posted on 2004-08-28
4
236 Views
Last Modified: 2010-04-17
How do I reset the on error statement?  Example:

on error goto ErrOccured
msgbox "hello world"

'starting here I don't want errors to goto ErrOccured and I may not have any further error checking in place so undesired effects could occur if things went to ErrOccured

BTW is there a way to goto an error trap and then back to your code without goto statements?
0
Comment
Question by:bluedragon99
[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
4 Comments
 
LVL 1

Author Comment

by:bluedragon99
ID: 11922029
what would be a good way to error check this for example:

Open OptionsFrm.LoggingPath.Text For Append As #2
       Print #2, "Test"
Close #2
0
 
LVL 22

Accepted Solution

by:
cookre earned 250 total points
ID: 11922173
To disable error handling:

on error goto 0


For the example:

on error goto oops
Open OptionsFrm.LoggingPath.Text For Append As #2
on error goto 0
Print #2, "Test"
Close #2



0
 
LVL 3

Assisted Solution

by:Stimphy
Stimphy earned 250 total points
ID: 11923691
Try This...

Private sub ErrorExample()
On Error Goto ErrHand
    msgbox "hello world"
On Error Resume Next 'Program execution will continue ignoring all errors... use sparingly or line by line
   msgbox "hello world"
   If Err.Number > 0 Then
       'An Error Occured
   End If
On Error Goto 0  'Disables Error Handling as stated by cookre... but your program execution will stop
   MsgBox "hello world"
Exit sub
ErrHand:
   Msgbox Err.Number & " " & err.Description
   Resume Next 'Causes the next line after the error to be executed
   Resume        'Causes the line that caused the error to be re-executed.
End Sub

Regaurds,
Dave
0
 
LVL 5

Expert Comment

by:WesleySaysHi
ID: 11923997
Use:

   on error goto ErrOccured

to jump to ErrOccured when there is an error.

Use:

   on error Resume Next

to jump to the next line of code without going to ErrOccured.

This is the most simple way.
0

Featured Post

Technology Partners: 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

A short article about a problem I had getting the GPS LocationListener working.
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

738 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