Results 1 to 3 of 3

Thread: RTF characters

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Location
    Stow, OH USA
    Posts
    6

    Post

    I am trying to run through an RTF control character by character and format the text through code based on its value.

    when I run into a linefeed or a carriage return, I am stopped. The code does not recognize the chr$(13) nor the chr$(10), and will not accept these as valid selstart and sellength positions.

    Does anyone know a way to determine if a character location in an RTF control is a line feed or a carriage return?

    Thanks in advance.

  2. #2
    Addicted Member
    Join Date
    May 1999
    Location
    Californ-I- A
    Posts
    207

    Post

    If that code isn't quite what you're looking for, although I'm sure it'll work better than this, but I've run into the same thing while making HTML editors and such. What I found, is that the chr(10) and chr(13) together form one line feed charactor. You can't use these as selstart charactors though because they are hidden as far as the selection is concerned. Just set you selstart to where the chr(10) charactor is plus one ... or is it the chr(13) that's last?

    Well, just remember to set your selstart property to one more than the line feed charactor(s). You may also want to try the vbLf instead of chr(10) and chr(13).

    For the most part, wherever there's a chr(10) there was a chr(13) with it, so for finding lines you can use just one, ir instr(1, txtRTF.text, chr("10")).

    If you are trying to do some sort of syntax highlighting, a word of advice, although it would be rather complicated, is to look into parsing and sub classing and so on, for it would be alot faster. Good luck

    ------------------
    Micah Carrick
    Ordinary joe, only not named joe.
    http://micah.carrick.com
    [email protected]
    ICQ: 53480225



  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    If I understand you correctly, you want to format your text line by line. If this is the case then you can use a couple of API calls to get every line for your RichTextBox:

    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_GETLINECOUNT = &HBA
    Private Const EM_LINEINDEX = &HBB
    Private Const EM_LINELENGTH = &HC1
    
    Private Sub Command1_Click()
        Dim strBuffer As String
        Dim lngLineLength As Long
        Dim lRet As Long
        Dim i As Long
        Dim lngCount As Long
        Dim lngIndex As Long
        Dim strFullString As String
        
        lngCount = SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0)
        
        For i = 0 To lngCount - 1
            lngIndex = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, i, 0)
            lngLineLength = SendMessage(RichTextBox1.hwnd, EM_LINELENGTH, lngIndex, 0)
            strBuffer = Space(lngLineLength)
            Call SendMessageString(RichTextBox1.hwnd, EM_GETLINE, i, ByVal strBuffer)
            'strBuffer now holds the line of text
            'Format it the way you want it and
            'append it to the Full string
            strFullString = strFullString & strBuffer & vbCrLf
        Next
        'Replace the text in the RichTextBox with the formated string
        RichTextBox1.Text = strFullString
    End Sub
    I hope this what you're looking for,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


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