Anyone know why the code below returns an "Run-time error '76' - path not
found" error?

The file (sFileName) does exist, as does the path

************************************
Private Sub LoadFile(sFileText As String, sFileName As String)
Dim f As Long
f = FreeFile
Open sFileName For Input As #f
sFileText = StrConv(InputB$(LOF(f), f), vbUnicode)
Close #f
End Sub
************************************

Re: Using Files by Milo

Milo
Fri Dec 03 09:34:51 CST 2004

It seems that sFileName that you are specifying does not exist.



Try using a function to return a string

**********************************************************
Private Function LoadFile(sFileName As String) As String
Dim f As Long
f = FreeFile
Open sFileName For Input As #f
LoadFile = StrConv(InputB$(LOF(f), f), vbUnicode)
Close #f
End Function
**********************************************************

You can then call this by using this:


Text1.Text = LoadFile("C:\textfile.txt")

Many Regards,
Milo

Re: Using Files by Phill

Phill
Fri Dec 03 09:39:06 CST 2004

"Billy" <Billy@discussions.microsoft.com> wrote in message
news:5F449BF5-F616-4B70-A61D-FF2812F1217D@microsoft.com...
> Anyone know why the code below returns an "Run-time error '76'
> - path not found" error?
>
> The file (sFileName) does exist, as does the path
>
> Private Sub LoadFile(sFileText As String, sFileName As String)
> Dim f As Long
> f = FreeFile
> Open sFileName For Input As #f
> sFileText = StrConv(InputB$(LOF(f), f), vbUnicode)
> Close #f
> End Sub

The Open Statement is pretty reliable where "Path not found" errors
are concerned. If it says the path doesn't exist, it probably doesn't
or, at least, the user account this is running under doesn't have
permissions to see it.

BTW, get in to the habit of using "ByVal" and "ByRef" in your function
declarations, as in

Private Sub LoadFile( _
ByRef sFileText As String _
, ByVal sFileName As String _
)
. . .

If you upgraded your existing code to VB.Net, you'd start getting
some even /stranger/ problems.

HTH,
Phill W.



Re: Using Files by Ken

Ken
Fri Dec 03 09:38:28 CST 2004

"Billy" <Billy@discussions.microsoft.com> wrote in message
news:5F449BF5-F616-4B70-A61D-FF2812F1217D@microsoft.com...
> Anyone know why the code below returns an "Run-time error '76' - path not
> found" error?
>
> The file (sFileName) does exist, as does the path
>
> ************************************
> Private Sub LoadFile(sFileText As String, sFileName As String)
> Dim f As Long
> f = FreeFile
'Try......
If FileExists(sFileName) Then
> Open sFileName For Input As #f
> sFileText = StrConv(InputB$(LOF(f), f), vbUnicode)
> Close #f
Else
MsgBox "File: " & sFileName & " not found"
End If
> End Sub
> ************************************

Private Function FileExists(FileName As String) As Boolean
On Error Resume Next
If Len(FileName) > 0 Then
FileExists = ((GetAttr(FileName) And vbDirectory) = 0)
Err.Clear
End If
End Function


--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..



Re: Using Files by Billy

Billy
Fri Dec 03 09:45:23 CST 2004

Thx for reply, Milo...but the text file DOES exist. I've stepped through the
code, checked the pth AND filename and it is where it should be.

"Milo" wrote:

> It seems that sFileName that you are specifying does not exist.
>
>
>
> Try using a function to return a string
>
> **********************************************************
> Private Function LoadFile(sFileName As String) As String
> Dim f As Long
> f = FreeFile
> Open sFileName For Input As #f
> LoadFile = StrConv(InputB$(LOF(f), f), vbUnicode)
> Close #f
> End Function
> **********************************************************
>
> You can then call this by using this:
>
>
> Text1.Text = LoadFile("C:\textfile.txt")
>
> Many Regards,
> Milo
>

RE: Using Files by Billy

Billy
Fri Dec 03 09:49:05 CST 2004

MY most humble apologies.

In my rush to try to fix this program, the path was incorrect "by one
character" - is that not always the case!!

I'm very, very sorry for wasting your time....thank you for taking the time
to reply.

As for the code, I absolutely use ByRef and ByVal - ALWAYS. This code was
written by someone else...I am merely trying to keep it going. It annoys me
when Byref and Byval are not used....I know Byref is the default and alot of
people leave it off because of this, but I don't...I am always explicit in
what I am passing and how I am passing it.

Again...sorry for wasting your time.

"Billy" wrote:

> Anyone know why the code below returns an "Run-time error '76' - path not
> found" error?
>
> The file (sFileName) does exist, as does the path
>
> ************************************
> Private Sub LoadFile(sFileText As String, sFileName As String)
> Dim f As Long
> f = FreeFile
> Open sFileName For Input As #f
> sFileText = StrConv(InputB$(LOF(f), f), vbUnicode)
> Close #f
> End Sub
> ************************************

Re: Using Files by Bob

Bob
Fri Dec 03 09:50:05 CST 2004

"Billy" <Billy@discussions.microsoft.com> wrote in message
news:06DB8B25-CD21-4FAD-9CC0-DCD487A79B70@microsoft.com
> Thx for reply, Milo...but the text file DOES exist. I've stepped
> through the code, checked the pth AND filename and it is where it
> should be.

Try the FileExists test that was suggested; either you have a typo in the
path and are misreading it or you don't have access to the file or
directory.


--
Reply to the group so all can participate
VB.Net... just say "No"