|
-
May 12th, 2007, 01:34 AM
#1
Thread Starter
Lively Member
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.
-
May 12th, 2007, 02:11 AM
#2
Hyperactive Member
Re: File not Find Problem
 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! 
-
May 12th, 2007, 03:20 AM
#3
Re: File not Find Problem
No no! would be better than that! 
All you have to do is check if the file exists and if it doesn't create it
-
May 12th, 2007, 03:26 AM
#4
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
-
May 12th, 2007, 03:30 AM
#5
Re: File not Find Problem
You forgot the Gavio
-
May 12th, 2007, 04:36 AM
#6
Thread Starter
Lively Member
Re: File not Find Problem
if i used :
On Error Resume Next
the program is hanged(not respond)
-
May 12th, 2007, 04:42 AM
#7
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
-
May 12th, 2007, 03:40 PM
#8
Re: File not Find Problem
 Originally Posted by Hell-Lord
You forgot the Gavio 
Please, read Hack's post...
-
May 13th, 2007, 04:44 AM
#9
Thread Starter
Lively Member
Re: File not Find Problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|