Results 1 to 3 of 3

Thread: RTF

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Does anybody know how to count number of characters in RTF? I used a Len function but it counts every character (when I hit enter it counts it as 2 chars). I want just the number of chars with and without spaces.
    Thanks in advance

    ------------------
    Visual Basic Programmer (at least I want to be one)
    -----------------
    PolComSoft
    You will hear a lot about it.



  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If you have VB6.0 you have the Ever Handy Replace Function which you can use, eg.
    Code:
    Private Sub Command1_Click()
        MsgBox "Total Chars: " & Len(RichTextBox1.Text) & vbCrLf & _
        "Chars, No CRLFs: " & Len(Replace(RichTextBox1.Text, vbCrLf, "")) & vbCrLf & _
        "Chars, NO CRLFs, No Spaces: " & Len(Replace(Replace(RichTextBox1.Text, vbCrLf, ""), " ", ""))
    End Sub
    Otherwise you can use the SendMessage API with the EM_GETLINECOUNT Message to Calculate the Number of Characters excluding CRLFs, eg.
    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 Const EM_GETLINECOUNT = &HBA
    
    Private Sub Command1_Click()
        MsgBox "Chars, Excluding CRLF: " & Len(RichTextBox1.Text) - (2 * (SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0) - 1))
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Unfortunately I don't have VB6 but the second function seems to work. Thanks Aaron.

    ------------------
    Visual Basic Programmer (at least I want to be one)
    -----------------
    PolComSoft
    You will hear a lot about it.



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