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 :)
Re: Richtextbox Change color of define word URGENT PLEASE
anybody has an idea please ?
Re: Richtextbox Change color of define word URGENT PLEASE
Re: Richtextbox Change color of define word URGENT PLEASE
that's not really what i want because,
id like to choose some important words like private,int, etc and define that when this word appear in the rtb, that this word change color for the color ive already define
but the link you give me is a good start
thanks
any other idea ?
Re: Richtextbox Change color of define word URGENT PLEASE
try this, i made it a while ago and it checks through a rich text box and compares each word with a list of keywords(also supplied) and turns them blue. it also checks for anything after a ' and turns it green and ignores writing in " quotations to imitate the vb editor. copy some code into it and take a look, it sounds like this is the kind of thing you want to do.
Vb code formatter
Re: Richtextbox Change color of define word URGENT PLEASE
Have you seen This Post Yet?
Re: Richtextbox Change color of define word URGENT PLEASE
thanks guys , ill look at this this morning and give you some feedback
Re: Richtextbox Change color of define word URGENT PLEASE
Ok thanks you it works, i found something on msdn and it help me to conclude that problem
i use that code
Private Sub tvw_NodeClick(ByVal Node As MSComctlLib.Node)
Dim i As Integer
i = 0
Dim retour As Integer
Dim word(3) As String
word(0) = "range"
word(1) = "sensor"
word(2) = "in"
While i < 3
' Statement block to be executed for each value of counter.
retour = FindMyText(word(i))
'select case
If (retour >= 0) Then
rtbCaracteristique.SelText = word(i)
rtbCaracteristique.SelStart = retour
rtbCaracteristique.SelLength = Len(word(i))
Select Case word(i)
Case "range": rtbCaracteristique.SelColor = vbRed
Case "sensor": rtbCaracteristique.SelColor = vbGreen
Case "in": rtbCaracteristique.SelColor = vbBlue
End Select
MsgBox "trouve"
Else
MsgBox "pas trouve"
End If
i = i + 1
rtbCaracteristique.SelStart = 0
Wend
End Sub
with the help of the method find on the msdn
thanks