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
Printable View
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
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