Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSeparate an RTF file into paragraphs in separate Rich Text Box controls
DescriptionThis example shows how to separate an RTF file into paragraphs in separate Rich Text Box controls in Visual Basic 6.
KeywordsRTF, rich text, rich text box, RichTextBox, paragraphs
CategoriesControls, Strings
 
When the program starts, it uses the rchWholeFile Rich Text Box control's LoadFile method to load an RTF file.

Next the program searches through the control's text for the vbCrLf strings that mark the end of paragraphs. It selects the paragraphs' text and uses the SelRTF property to copy the text and its formatting codes into different Rich Text Box controls.

 
Private Sub Form_Load()
Dim file_name As String
Dim i As Integer
Dim txt As String
Dim pos1 As Integer
Dim pos2 As Integer

    ' Load the file.
    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = _
        file_name & "\"
    file_name = file_name & "books.rtf"
    rchWholeFile.LoadFile file_name

    ' Break the file into paragraphs.
    txt = rchWholeFile.Text
    pos1 = 0
    For i = 0 To rchParagraph.UBound
        pos2 = InStr(pos1 + 1, txt, vbCrLf)
        If pos2 = 0 Then pos2 = Len(txt)
        rchWholeFile.SelStart = pos1
        rchWholeFile.SelLength = pos2 - pos1
        rchParagraph(i).SelStart = 0
        rchParagraph(i).SelLength = _
            Len(rchParagraph(i).Text)
        rchParagraph(i).SelRTF = rchWholeFile.SelRTF
        rchParagraph(i).SelStart = 0
        rchParagraph(i).SelLength = 0
        pos1 = pos2 + 1
    Next i
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated