VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Allows a user to type text into a richtext box control and have the selcolor change when certain ke

by CodeTroll (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 6th March 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



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.


Download this snippet    Add to My Saved Code

Allows a user to type text into a richtext box control and have the selcolor change when certain ke Comments

No comments have been posted about Allows a user to type text into a richtext box control and have the selcolor change when certain ke. Why not be the first to post a comment about Allows a user to type text into a richtext box control and have the selcolor change when certain ke.

Post your comment

Subject:
Message:
0/1000 characters