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
Re: File not Find Problem
No no! would be better than that! :p
All you have to do is check if the file exists and if it doesn't create it ;)
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
Re: File not Find Problem
Re: File not Find Problem
if i used :
On Error Resume Next
the program is hanged(not respond)
Re: File not Find Problem
Forget On Error Resume Next even exists.
Try this:
VB Code:
If Dir$("App.Path & "\xx.txt"") <> vbNullString Then
Open App.Path & "\xx.txt" For Input As #f 'file exists so open it
Else
Open App.Path & "\xx.txt" For Append As #f 'file does not exist so create it
End If
Re: File not Find Problem
Quote:
Originally Posted by Hell-Lord
Please, read Hack's post...
Re: File not Find Problem