PDA

View Full Version : [SOLVED] Question About the "Resume" Statement



Cyberdude
06-16-2005, 01:57 PM
When I read the VBE Help about the Resume statement, they listed three variations. The first of the three says that by not specifying an argument it will return control to the statement that made the error which On Error trapped.
That sounds like it would be an invitation to create an infinite loop. Under what conditions would one want to return to the same statement that caused an error? :doh:

johnske
06-16-2005, 02:11 PM
...... Under what conditions would one want to return to the same statement that caused an error? :doh:

Hi Cyber,

If your error-handling procedure included a procedure to (say) alter a variable that raised the initial error you may then want to clear the error and try again with the alteration.

But yes, the potential is there for an infinite loop so it's generally best to try to avoid this situation altogether

Regards,
John

Bob Phillips
06-16-2005, 02:30 PM
Under what conditions would one want to return to the same statement that caused an error?

Whilst I might be loathe to use it myself, the example in Help gives a good case for it.



Sub ResumeStatementDemo()
On Error GoTo ErrorHandler
Open "TESTFILE" For Output As #1
Kill "TESTFILE" ' Attempt to delete open file.
Exit Sub ' Exit Sub to avoid error handler.
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 55 ' "File already open" error.
Close #1 ' Close open file.
Case Else
' Handle other situations here....
End Select
Resume ' Resume execution at same line
' that caused the error.
End Sub

Cyberdude
06-16-2005, 03:28 PM
OK, I get it. It would seem that you should avoid it unless you really know what you are doing. Thanks!