-
Code:
Private Sub MakeColored()
For x = 1 To Len(rtfbox.Text)
If Mid(rtfbox.Text, x, Len("SELECT")) = "SELECT" Then
rtfbox.SelStart = x - 1
rtfbox.SelLength = Len("SELECT")
rtfbox.SelColor = vbBlue
rtfbox.SelLength = 0
rtfbox.SelColor = vbBlack
x = (x - 1) + Len("SELECT")
Else
rtfbox.SelColor = vbBlack
End If
Next x
rtfbox.SelStart = Len(rtfbox.Text)
End Sub
I havve this code to look for the word "SELECT" in a RichTextBox, and if found, color it blue. This works the first time, but if I run the code again, it colors evrything blue! Who can tell me why?
-
<?>
It doesn't for me. Works fine..even if I click it 10 times the only work blue is Select
-
here's the thing, It does that for me too, but then I go to the next line in the box, add some more text, and run it again, and that's where it screws up...I don't know...
EDIT
I have it on the KeyPress event and it runs when the ENTER key is pressed...
-
-
Reset all the text to black before colouring the text again. Ok, so it's a brute force approach, but it should work.
- gaffa
-
Alright, I'll try that...
-
cool, that worked, thanks gaffa...