Results 1 to 4 of 4

Thread: Reading from .rtf file [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    105

    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:
    1. Dim strData As String
    2.     Dim hFile As Long
    3.     Dim sFilename As String
    4.    
    5.     sFilename = ".\file.dat"
    6.     hFile = FreeFile
    7.     Open sFilename For Input As #hFile
    8.       strData = Input$(LOF(hFile), hFile)
    9.     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
    Last edited by langals; May 11th, 2005 at 10:44 AM. Reason: Resolved

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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:
    1. Dim strData As String
    2. Dim hFile As Long
    3. Dim sFilename As String
    4.    
    5. sFilename = ".\file.dat"
    6. hFile = FreeFile
    7. Open sFilename For Input As #hFile
    8.     Do Until EOF(hFile)
    9.         strData = Input$(LOF(hFile), hFile)
    10.     Loop
    11. Close #hFile

    Cheers,

    RyanJ
    Last edited by sciguyryan; May 11th, 2005 at 10:35 AM.
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Location
    South Africa
    Posts
    105

    Re: Reading from .rtf file

    Thanks. That is so much easier than what I was trying.

    langals

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width