PDA

Click to See Complete Forum and Search --> : RTF characters


HariSeldon
Dec 9th, 1999, 09:26 PM
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.

MicahCarrick
Dec 10th, 1999, 01:04 AM
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
micah@carrick.com
ICQ: 53480225

Serge
Dec 10th, 1999, 11:47 AM
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:


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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)