Find a particular word and change the color of it (timer)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BarryM
    New Member
    • Mar 2008
    • 32

    Find a particular word and change the color of it (timer)

    vb 2005
    Hi, in my program i have a rich text box with some text entered in by the user. While they are typing a timer is running that searches the rtb for a word which is "theword" in this case and if it does find a match it changes the word in the text box to blue. Same as vb 2005 puts any conditions in blue e.g if, else, end, and, or etc.

    Code:
    Private intPosition As Integer
     Static intStart As Integer
            Dim text As String = txtcode.SelectedText
            Dim objType As Object
            objType = CompareMethod.Text
            intposition = 1
            intStart = InStr(intPosition, txtcode.Text, "theword", objType)
            If intStart > 0 Then
                txtcode.SelectionStart = intStart - 1
                txtcode.SelectionLength = 5
                txtcode.SelectionColor = Color.Blue
            End If
    That piece of coding comes up with 3 logic errors. Just a list of things wrong with it -
    1 it highlights the word but yet i haven't told it to
    2 it changes all of the text to blue
    3 it doesn't work

    note: because the coding highlights the word when the press space or another key the word is deleted

    does anybody know how to help on this, if can please reply
Working...