Solved

Visual basic simple error checking question On error

Posted on 2004-08-28
4
234 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

809 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