QWERTY
Nov 5th, 1999, 09:57 AM
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.
Aaron Young
Nov 5th, 1999, 10:23 AM
If you have VB6.0 you have the Ever Handy Replace Function which you can use, eg.
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.
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
aarony@redwingsoftware.com
adyoung@win.bright.net
QWERTY
Nov 5th, 1999, 10:47 AM
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.