|
-
Jan 31st, 2000, 03:42 AM
#1
I am trying to number each line of text in a rich text box without much success. It is my aim to number each line in tens. Does anybody have any ideas. All help much appreciated.
eg.
10 I am trying to number each line of text 20 in a rich text box without much success. 30 It is my aim to number each line in tens. 40 Does anybody have any ideas. All help
50 much appreciated.
ta.
Chris Brand.
-
Jan 31st, 2000, 03:53 AM
#2
Hyperactive Member
You could always look through the text for vbcr and vblf (char(13) and char(10)) and then put the number afterwards.
dim intI as integer, intLineCnt as integer, strtemp as string
dim intJ as integer
intLineCnt = 10
if txtRTF.text <> "" then
for intI = 1 to len(txtRTF.text) -1
intJ = inString(txtRTF.text, vbcr & vblf)
if intJ <> 0 then
strtemp = strtemp & mid(txtRTF.text, inti, intj +2) & intLineCnt
intLineCnt = intLineCnt + 10
intI = intJ + 3
else
strtemp = strtemp & mid(txtRTF.text, intI)
exit for
end if
next intI
end if
txtRTF.text = strtemp
May have to tweak the intJ + 2 and 3 etc to make sure it brackets the carraige return and line feed correctly but that should work.
[This message has been edited by netSurfer (edited 01-31-2000).]
-
Jan 31st, 2000, 04:13 AM
#3
There is a much faster way:
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_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Private Sub Command1_Click()
Dim lCount As Long
Dim strBuffer As String
Dim arrBuffer() As Byte
Dim lIndex As Long
Dim lLen As Long
Dim i As Long
With RichTextBox1
lCount = SendMessage(.hwnd, EM_GETLINECOUNT, 0, 0)
For i = 0 To lCount - 1
lIndex = SendMessage(.hwnd, EM_LINEINDEX, i, 0)
lLen = SendMessage(.hwnd, EM_LINELENGTH, lIndex, 0)
ReDim arrBuffer(lLen)
arrBuffer(0) = lLen And 255
arrBuffer(1) = lLen And 256
Call SendMessage(.hwnd, EM_GETLINE, i, arrBuffer(0))
strBuffer = strBuffer & CStr((i + 1) * 10) & " " & Left$(StrConv(arrBuffer, vbUnicode), lLen) & vbCrLf
Next
.Text = strBuffer
End With
End Sub
Regards,
------------------
Serge
Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 01-31-2000).]
-
Jan 31st, 2000, 05:52 AM
#4
Thanks for your prompt replies.
I'm now off to give them both a try
CB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|