Click to See Complete Forum and Search --> : How can I tell if a file was opened sucessfully?


Matt Hauser
November 10th, 1999, 05:01 PM
Hello there!

I know how to open, write to, and close a file in visual basic, but how can I tell if a file was opened sucessfully?

If there's an error opening the file, I would like to display a message box indicating so.

Thanks in advance!

Matt

Lothar Haensler
November 11th, 1999, 01:45 AM
errors upon opening a file will trap a runtime error:

on error goto errhandler
dim hFile as integer
hFile = freefile
' the following will raise an error
open "yourfile" for input as #hFile
' if we arrived here, the file was opened successfully
...
exit sub
errhandler:
msgbox err.number & " " & err.description
end sub