Solved

Visual basic simple error checking question On error

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

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

16 Experts available now in Live!

Get 1:1 Help Now