Allows a user to type text into a richtext box control and have the selcolor change when certain ke
Allows a user to type text into a richtext box control and have the selcolor change when certain keywords are found. (Length of string does
Rate Allows a user to type text into a richtext box control and have the selcolor change when certain ke
(2(2 Vote))
place = 1 'Set all the values to 1, for when we do the first search.
flag1 = 1
flag2 = 1
End Sub
Private Sub Text1_Change() 'we put the code in the change event (i.e. while typing)
flag1 = InStr(place, Text1.Text, "joe") 'Strings we are searching for
flag2 = InStr(place, Text1.Text, "bark")
If flag1 > 0 Then 'If we find "joe" then do the following:
place = flag1 + 1 'Place allows us to take the last place we found the string and search from there.
Text1.SelColor = vbGreen 'set the color to green.
End If
If flag2 > 0 Then 'If we find bark then do the following:
place = flag2 + 1 'As stated above.
Text1.SelColor = vbRed 'Set the color to red
End If
End Sub
'If one so wishes one could create an array for colors then use a for loop
'within the change event to identify different colors. Use the for loop in
'conjunction with a Select Case, and it eliminates a lot of the if - then
'statements. Makes it easier to read. This example is good if you need
'to pass certain data through a function for color analysis. Just dump the
'code, make some minor corrections, and you're good to go. Have fun, any
'questions let me know.
Allows a user to type text into a richtext box control and have the selcolor change when certain ke Comments
No comments yet — be the first to post one!
Post a Comment