Reading from .rtf file [RESOLVED]
Hi there
I am trying to read all of the data from a .rtf file and write it to a Rich Text Box. Now, I have done the same with a .dat file before, with the following code, and it works:
VB Code:
Dim strData As String
Dim hFile As Long
Dim sFilename As String
sFilename = ".\file.dat"
hFile = FreeFile
Open sFilename For Input As #hFile
strData = Input$(LOF(hFile), hFile)
Close #hFile
But when I use file.rtf file in place of file.dat, then it throws the following error:
Run-time error '62'
Input past end of file
Any idea how I could make this work?
Many thanks
langals
Re: Reading from .rtf file
You know that the RichTextbox has a method called LoadFile which can do this for you :)
And, you could try something like this:
VB Code:
Dim strData As String
Dim hFile As Long
Dim sFilename As String
sFilename = ".\file.dat"
hFile = FreeFile
Open sFilename For Input As #hFile
Do Until EOF(hFile)
strData = Input$(LOF(hFile), hFile)
Loop
Close #hFile
Cheers,
RyanJ
Re: Reading from .rtf file
Thanks. That is so much easier than what I was trying.
langals
Re: Reading from .rtf file
Quote:
Originally Posted by langals
Thanks. That is so much easier than what I was trying.
langals
You are welcome langals :)
Cheers,
RyanJ