?
Solved

On error goto 0

Posted on 2003-02-23
4
Medium Priority
?
1,737 Views
Last Modified: 2013-11-13
What is On error goto 0 ? and how to use it ?
pls provide real sampe and explanation, thank you very much
0
Comment
Question by:bvlgary
[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

Expert Comment

by:robatdural
ID: 8006192
"On Error Goto 0" resets the direction of a previous on error statement. Reseting an On Error statement is a wise thing to do as it stops your program from unexpected branching.

eg

Private Sub readStringFromFile(inputStr as String)

' Set error trapping
On Error Goto myErrorTrap

'Try to open a file that doesn't exist
Open "C:\testFile.txt" for Input as #1
  Input #1, inputStr
Close 1

'reset error trapping
On Error Goto 0

Exit Sub

myErrorTrap:

  inputStr = "No File"
On Error Goto 0

End Sub

0
 
LVL 5

Accepted Solution

by:
JohnMcCann earned 200 total points
ID: 8006193
You can use On Error with the following

On Error Rsume Next      

If error ocurs continue at next statement.

Example
On Error Rsume Next      
a = 2 / 0
'Resumes here when error occurs (Ignores error)
msgbox err,description 'Error did occur

On Error GoTo Err_Handler

If an error occurs the next statement executed is directly under Err_Handler after the Err_Handler has been executed you would typically then resume execution at a given point

Examp;e

On Error GoTo Err_Handler

  a = 2 / 0

Exit_Handler:
   Exit Function
Err_Handler:
  'Resumes here when error occurs
  resume Exit_Handler

And finally

On Error GoTo 0

This disables any error handling  

Using the above example

On Error GoTo 0
a = 2 / 0

If you try and run this code the complier will spit out and error as it has not been trapped.

0
 

Expert Comment

by:StonedRaider
ID: 8006198
private sub Tesr()
0: on error goto 0
1: yor code here..., if an error
2: occurs, you will go to 0
3: so the code will execure again
end sub
0
 
LVL 1

Expert Comment

by:adp1970
ID: 8006362
The On Error GoTo 0 statement turns off error trapping within the current procedure.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

771 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