Results 1 to 6 of 6

Thread: [RESOLVED] RTF File to richtextboxes

  1. #1

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,177

    Resolved [RESOLVED] RTF File to richtextboxes

    Ok, my turn to play dumb....
    I have an rtf file something like this small example:

    Code:
    GEOGRAPHY
    Europe
    Asia
    Australia
    I know I can use the loadfile or Input functions to load the entire file into ONE richtextbox,

    as in:

    Code:
     Dim intFile As Integer
        intFile = FreeFile
        Open App.Path & "\myrtffile.rtf" For Input As intFile
        RichTextBox1.TextRTF = StrConv(InputB$(LOF(1), 1), vbUnicode)
        Close intFile
    but ....
    I want to load each line separately into richtextboxes (this example, 4) and retain the formatting (color/underlined/Etc).

    Simple example?

  2. #2
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    765

    Re: RTF File to richtextboxes

    You'll still need the initial RichTextBox to read and interpret the Rich Text File, then slice it up into individual lines from there.

    Try opening your Rich Text File in Notepad.
    It doesn't look anything like what you posted; all that "stuff" in there is the RichText markup that makes RichText what it is. (If you really want to scare yourself, try the same with an old-style .doc file!). You don't want to try making sense of all that yourself - there's a handy little Control available to do all that for you; the RichTextBox.

    Of course, that doesn't mean that your Users need to see this intermediate RichTextBox; it works just as well with its Visible property set to False.

    Regards, Phill W.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: RTF File to richtextboxes

    The issue you'll have trying to do this line by line, is that the current line you are reading may have been formatted by RTF codes that were read much earlier in the file. I think you'd have to keep track of those and apply it to each line you read, but that is oversimplifying the process. Phil's solution may be the easiest
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,177

    Re: RTF File to richtextboxes

    You'll still need the initial RichTextBox to read and interpret the Rich Text File, then slice it up into individual lines from there.
    So, you mean first load the file into a RTB (which can be invisible), then use functions like SelStart, SelLength and SelText to load each 'line' into other RTBs? Sounds like a pain...but guess that must be the best solution.

    --ps--yeah, I know about all that other 'stuff' when opening an rtf file in NotePad---of course, in Word, it 'appears' the way I want to see each line in separate RTBs.

  5. #5

    Thread Starter
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,177

    Re: RTF File to richtextboxes

    The issue you'll have trying to do this line by line, is that the current line you are reading may have been formatted by RTF codes that were read much earlier in the file.
    I see what you mean. If first two 'lines' are bold and underlined, and try to get just the first line, it won't have the formatting characters at the beginning and ending.

    Guess I'll play around with Phil's advice.

  6. #6
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,452

    Re: [RESOLVED] RTF File to richtextboxes

    Use the SelRtf property instead of SelText, and you should get all the formatting in your second RichTextBox.

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