Results 1 to 9 of 9

Thread: File not Find Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    82

    Question File not Find Problem

    hi for every one

    the following statements open txt file and read it :

    Code:
    Dim f As Integer
    f = FreeFile
    Open App.Path & "\xx.txt" For Input As #f
    but if (xx.txt) is deleted the compiler give me :

    run time error'53'
    file not find
    i want if the program not find file,i want to execute next statement without show error .
    what is the code use to ignore that error.

  2. #2
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: File not Find Problem

    Quote Originally Posted by mse07
    hi for every one

    the following statements open txt file and read it :

    Code:
    Dim f As Integer
    f = FreeFile
    Open App.Path & "\xx.txt" For Input As #f
    but if (xx.txt) is deleted the compiler give me :



    i want if the program not find file,i want to execute next statement without show error .
    what is the code use to ignore that error.

    Try

    Code:
    on error resume next
    If an answer to your question has been helpful, then please, Rate it!

  3. #3
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: File not Find Problem

    No no!
    Code:
    On Error End
    would be better than that!
    All you have to do is check if the file exists and if it doesn't create it

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: File not Find Problem

    Code:
    Private Sub Form_Load()
        Dim f As Integer
        Dim sFileName As String
    
        f = FreeFile
        sFileName = App.Path & "\xx.txt"
    
        If FileExist(sFileName) Then
            Open sFileName For Input As #f
                '...
            Close #f
        End If
    
        'continues here...
    End Sub
    
    Public Function FileExist(ByVal sFileName As String) As Boolean
        FileExist = (Len(Dir$(sFileName, vbHidden + vbSystem)) > 0)
    End Function

  5. #5
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: File not Find Problem

    You forgot the
    vb Code:
    1. On Error Resume Next
    Gavio

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    82

    Re: File not Find Problem

    if i used :

    On Error Resume Next

    the program is hanged(not respond)

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: File not Find Problem

    Forget On Error Resume Next even exists.

    Try this:
    VB Code:
    1. If Dir$("App.Path & "\xx.txt"") <> vbNullString Then
    2.    Open App.Path & "\xx.txt" For Input As #f 'file exists so open it
    3. Else
    4.    Open App.Path & "\xx.txt" For Append As #f 'file does not exist so create it
    5. End If

  8. #8
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: File not Find Problem

    Quote Originally Posted by Hell-Lord
    You forgot the
    vb Code:
    1. On Error Resume Next
    Gavio
    Please, read Hack's post...

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    82

    Re: File not Find Problem

    thank you for help me

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