|
-
May 11th, 2005, 09:38 AM
#1
Thread Starter
Lively Member
Richtextbox Change color of define word URGENT PLEASE
Hi, i find on this forum info about changing the colors of a word in a richtextbox but id like to know if we can change more than one word's color.
cause presently when i change the color of one word it works but if id like to change another word in the same rtb, the color change but the other one become black like the other one..
Private Sub HighlightText(sKeyword As String, iColour As Long)
Dim nStart As Integer, sPrevChar As String, sNextChar As String
With rtbCaracteristique
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = vbBlack
.SelStart = Len(.Text)
End With
nStart = InStr(1, LCase(rtbCaracteristique.Text), sKeyword, vbTextCompare)
Do While nStart <> 0
If nStart > 1 Then
sPrevChar = Mid$(rtbCaracteristique.Text, nStart - 1, 1)
Else
sPrevChar = " "
End If
If Len(rtbCaracteristique.Text) >= nStart + Len(sKeyword) Then
sNextChar = Mid$(rtbCaracteristique.Text, nStart + Len(sKeyword), 1)
Else
sNextChar = " "
End If
If (sPrevChar = Chr(32) Or sPrevChar = Chr(13) Or _
sPrevChar = Chr(10) Or sPrevChar = Chr(9)) And _
(sNextChar = Chr(32) Or sNextChar = Chr(13) Or _
sNextChar = Chr(10) Or sNextChar = Chr(9) Or sNextChar = ".") Then
With rtbCaracteristique
.SelStart = nStart - 1
.SelLength = Len(sKeyword)
.SelColor = iColour
.SelText = StrConv(sKeyword, vbProperCase)
.SelStart = Len(rtbCaracteristique.Text)
.SelColor = iColour
End With
End If
nStart = InStr(nStart + Len(sKeyword), LCase(rtbCaracteristique.Text), sKeyword, vbTextCompare)
Loop
End Sub
so if any ideas,,,,let me know
thanks
Last edited by DesyM; May 12th, 2005 at 10:11 AM.
Reason: urgent please
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
|