Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handling Errors during Execution 2

Status
Not open for further replies.

kellyputty

Technical User
Jul 28, 2005
29
US
The following code always ends in a runtime error instead of being handled by the On Error statement. Any idea what I am doing wrong?
<code>
Private Sub cmdOpenFile_Click()
On Error GoTo HandleErrors
Open txtPathName.Text For Input As #1
Dim S As String
Input #1, S
cmdOpenFile_Click_Exit:
Exit Sub
HandleErrors:
Select Case Err.Number
Case 53
MsgBox "File not found."
Case 71
MsgBox "Disk not Ready."
Case 76
MsgBox "Path not found."
Case Else
Err.Raise Err
End Select
Resume
End Sub
</code>
Thanks in advance,
kellyputty
 


Run time error on WHAT statement?

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Any of them. It appears that if I test error 53,for example, I always get the VB run-time error instead of the MsgBox I coded for that. My code isn't handling the errors at all. Not sure what to do different.

Thanks for the help Skip.
KellyPutty
 


Why are you using Err.Raise?

What did you want to happen?

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
I thought it would raise others errors I haven't coded for. If I leave it out I still get the same result. For example:

I purposely enter a file that doesn't exist in the txtPathName.Text
I get a VB run-time error instead of the
MsgBox "File not found." (Which is what I want)

Thanks again,
KellyPutty
 


You might want to check your error numbers

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
The numbers are correct, even the VB run-time error shows the same error numbers.
KellyPutty
 
Go into Tools Options. On the General tab, see if you have Break on All Errors selected. If so, you have disabled your error handling. Select either of the other two options.

HTH

Bob
 


I got an err number of 75 for a path error.

Problem is with your approch and resume, ther is no error correction so you'll loop indefinitely.

Take a look at On Error resume next.



Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Skip and Bob.

Thank you that worked.

I had my error handling disabled and an infinite loop because of the resume.

Grateful,
KellyPutty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top