?
Solved

On error goto 0

Posted on 2003-02-23
4
Medium Priority
?
1,758 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
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

578 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