|
-
May 2nd, 2001, 12:27 PM
#1
Catching a file open error?
Hello! I'd like to be able to catch an error upon attempting to open a file. Currently, if the file im trying to open is already in use by another app, my app crashes. I'd rather keep my program running and post a message stating the file is currently in use.
Any thoughts?
Thanks!!
CR8YrF8
-
May 2nd, 2001, 12:40 PM
#2
Re: Catching a file open error?
on error Goto ErrHndlr
Open Filename .....
on error Goto 0
....
Exit Sub
ErrHndlr:
Msgbox ....
-
May 2nd, 2001, 01:15 PM
#3
Re: Catching a file open error?
Hmm ok here is what I have. This gives me an undefined label error in the line On Error GoTo ErrHndlr.
on error GoTo ErrHndlr
Open "myFile" for Append as #1
on error GoTo 0
print #1, "test"
Close #1
End Sub
ErrHndlr:
dim temp
temp = MsgBox("error", vbYesNo, "File Write error")
What am i doing wrong?
Thanks again
CR8YrF8
-
May 2nd, 2001, 01:19 PM
#4
Re: Catching a file open error?
Doh I've got it. I was using "End Sub" rather than "Exit Sub". End sub only goes at the actual end, and exit sub goes before the error handling to avoid unwanted execution.
Thanks
CR8YrF8
-
May 2nd, 2001, 01:19 PM
#5
Re: Catching a file open error?
Not End Sub, it should be Exit Sub
End Sub should be at the last of everything.
on error GoTo ErrHndlr
Open "myFile" for Append as #1
on error GoTo 0
print #1, "test"
Close #1
Exit Sub
ErrHndlr:
dim temp
temp = MsgBox("error", vbYesNo, "File Write error")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|