469,082 Members | 1,119 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,082 developers. It's quick & easy.

opening a file that exists, but says it doesn't

Hi there,
I am a newbie working from the Visual Basic Programmers Workbook. I have
created a text file called Origin.txt but when I go to open it I keep
getting a "file does not exist" error, although it definitely does.
Any ideas?

Here is code:

Private Sub cmdInputFile_Click()
Dim intYear As Integer
Dim intNSWScore As Integer
Dim intQLDScore As Integer

Me.Cls
'Use Dir to verify that the file exists:
If Dir("C:\Documents and Settings\Owner\My
Documents\VBWork\Expressions\Origin.txt") = "" Then
MsgBox "File not found"
'Take a premature exit:
Exit Sub
End If
Open "C:\Documents and Settings\Owner\My
Documents\VBWork\Expressions\Origin.txt" For Input As #1
Print "Year", "NSW", "QLD"
Do While Not EOF(1)
Input #1, intYear, intNSWScore, intQLDScore
'Print to the form:
Print intYear, intNSWScore, intQLDScore
Loop
Close #1
End Sub
Jul 17 '05 #1
1 2628
I tried it and it worked fine. I suspect the file you are looking for may
exist in a location other than the one you are expecting to find it. Place
the Origin.txt file in the same location as your application and adapt your
code to look for it there using App.Path.

"V Bradley" <vo*******@yahoo.com> wrote in message
news:20*********************@news02.tsnz.net...
Hi there,
I am a newbie working from the Visual Basic Programmers Workbook. I have
created a text file called Origin.txt but when I go to open it I keep
getting a "file does not exist" error, although it definitely does.
Any ideas?

Here is code:

Private Sub cmdInputFile_Click()
Dim intYear As Integer
Dim intNSWScore As Integer
Dim intQLDScore As Integer

Me.Cls
'Use Dir to verify that the file exists:
If Dir("C:\Documents and Settings\Owner\My
Documents\VBWork\Expressions\Origin.txt") = "" Then
MsgBox "File not found"
'Take a premature exit:
Exit Sub
End If
Open "C:\Documents and Settings\Owner\My
Documents\VBWork\Expressions\Origin.txt" For Input As #1
Print "Year", "NSW", "QLD"
Do While Not EOF(1)
Input #1, intYear, intNSWScore, intQLDScore
'Print to the form:
Print intYear, intNSWScore, intQLDScore
Loop
Close #1
End Sub

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.