Results 1 to 5 of 5

Thread: Extracting a line from a Rich Text Box

  1. #1
    Guest

    Post

    How would I extract 1 line from a rich text box, make some changes to it using a sub that i already wrote, and then put it back where it was with the changes.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    1.
    Find the line by splitting the text property between crlf's

    Then change the item in the splitted array and join them again and put them into the text.
    2.
    Or jump with instr to the right position, and extract the text with mid, while you have the start and end position stored. Then change the text and use left and mid to connect the left part, the text and the right part of the rtf.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest
    Could you write some code for it to help me on my way? Thanks...

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Ok the the split-join is probably easy, but i don't konw about the performance. I write the other later if you need it instead
    Code:
     Dim a
     a=split(rtfbox.text,vbcrlf)
     a(yourlinenumber)=Yourtext
     rtfbox.text=Join(a)
    If this doesn't work then it's because i use vb5, and i haven't seen how to use split and join functions, but they probably are used like this
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Actually, the right way to do it is to use APIs to get the line from the RichTextBox or TextBox:
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    Private Const EM_GETLINE = &HC4
    Private Const EM_LINEINDEX = &HBB
    Private Const EM_LINELENGTH = &HC1
    
    Private Sub Command1_Click()
        Dim strBuffer As String
        Dim lngLineLength As Long
        Dim lngIndex As Long
        
        'Get the Index for the first line
        'Third parameter in the function specifies the line number (zero based)
        lngIndex = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, 0, 0)
        'Get the length of the line
        lngLineLength = SendMessage(RichTextBox1.hwnd, EM_LINELENGTH, lngIndex, 0)
        'Prepare buffer
        strBuffer = Space(lngLineLength)
        'Get the line from RichTextBox
        Call SendMessageString(RichTextBox1.hwnd, EM_GETLINE, i, ByVal strBuffer)
    End Sub

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