Results 1 to 4 of 4

Thread: How do I prevent an error if a file is not found?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    11
    In my program, I want it to detect if a file is there - if it is not, then the necessary files and folders for my program haven't been created yet and will need to be. If it is there (which it would be after my program has been installed), then the program won't need installing.

    Code:
    Open Filepath & "\general\InstallDetect.txt" For Input As #FileName
    On Error GoTo InstallProgram
    Close #FileName
    Despite the On Error Statement, it still gives an error. How can I prevent this?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    first of all, you have to setup your error trap before the point that would cause an error, so like this :
    Code:
    On Error GoTo InstallProgram
    Open Filepath & "\general\InstallDetect.txt" For Input As #FileName
    
    Close #FileName
    but if you want to check if the file is there before you open it use this code :
    Code:
    If Len(Dir$(Filepath & "\general\InstallDetect.txt")) <>0 Then
    Open Filepath & "\general\InstallDetect.txt" For Input As #FileName
    '...
    Close #FileName
    End If
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    11
    Awesome - thanks a lot!

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    no problem
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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