CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    Davenport, Iowa, USA
    Posts
    158

    How can I tell if a file was opened sucessfully?

    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


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How can I tell if a file was opened sucessfully?

    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





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured