?
Solved

Visual basic simple error checking question On error

Posted on 2004-08-28
4
Medium Priority
?
240 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 1000 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 1000 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

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.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn different types of Android Layout and some basics of an Android App.
Progress
Introduction to Processes

777 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