RichTextBox Find and Highlight Line with prefix
I have a richtextbox,
My format is something like this
*blahblahblah (newline)
so one line per asterisk code.
I want to expand this beyond other pieces of code as well.
Such as ((Text)) and highlight color the whole phrase, so far that's what I'm faced with now.
But I found that somewhat on these forums. Right now I'm concerned about the above item right now.
I know this should be real simple. I just am not good at String Management, with RichTextBoxes
Much Thanks in Advance.
Re: RichTextBox Find and Highlight Line with prefix
You can use the .Find method of the rtb to selectively highlight text.
Re: RichTextBox Find and Highlight Line with prefix
Yea, I'm aware of that.
However each selection will be different and can be auto created
So possible phrases
*Hello
*Bye
*TTYL
each line would be globally colored whatever, on the change event.
Re: RichTextBox Find and Highlight Line with prefix
Re: RichTextBox Find and Highlight Line with prefix
I've been checking that thread for 2 weeks now.
I tried practically every search phrase on google and here to find the solution...
Try... Search... Then Last Possible Senario Ask...
Re: RichTextBox Find and Highlight Line with prefix
Are you looking to color each word that is prefixed with a * ?
If so, just search for the * and then from that starting point, search for a space or line feed and color what's inside.
Re: RichTextBox Find and Highlight Line with prefix
yes that is the plan. So I would use .Find and use Left functions.
Then carriage return is /n correct?
Re: RichTextBox Find and Highlight Line with prefix
Nope. Try the vbCrLf code.
Re: RichTextBox Find and Highlight Line with prefix
Quote:
Originally Posted by DJHotIce
Then carriage return is /n correct?
I believe /n is C/C++ syntax.
Re: RichTextBox Find and Highlight Line with prefix
Try this
VB Code:
Option Explicit
Dim lStart As Long
Dim lEnd As Long
Dim Found As String
Private Function FindNext(lStart As Long, lEnd As Long, Found As String) As Boolean
FindNext = False
If lStart = 0 Then lStart = -1
lStart = RTB.Find("*", lStart + 1)
If lStart < 0 Then Exit Function
lEnd = InStr(lStart + 1, RTB.Text, vbCrLf)
Found = Mid(RTB.Text, lStart + 1, lEnd - lStart - 1)
FindNext = True
End Function
Private Sub Command1_Click()
If Not FindNext(lStart, lEnd, Found) Then
MsgBox "All Words Found"
Else
'do your highlighting here
MsgBox "Found: " & Found
End If
End Sub
Private Sub Form_Load()
RTB.SelText = "This is a test" & vbCrLf
RTB.SelText = "*Find" & vbCrLf
RTB.SelText = "Don't Find" & vbCrLf
RTB.SelText = "*Hello" & vbCrLf
RTB.SelText = "*There" & vbCrLf
RTB.SelText = "Skip me" & vbCrLf
RTB.SelText = "*Get" & vbCrLf
End Sub