Results 1 to 10 of 10

Thread: RichTextBox Find and Highlight Line with prefix

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    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.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: RichTextBox Find and Highlight Line with prefix

    You can use the .Find method of the rtb to selectively highlight text.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    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.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: RichTextBox Find and Highlight Line with prefix

    See this thread for RTB tricks.

    http://www.vbforums.com/showthread.php?t=355994

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    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...

  6. #6
    Hyperactive Member Datacide's Avatar
    Join Date
    Jun 2005
    Posts
    309

    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.
    PHP in your FACE!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    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?

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: RichTextBox Find and Highlight Line with prefix

    Nope. Try the vbCrLf code.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: RichTextBox Find and Highlight Line with prefix

    Try this
    VB Code:
    1. Option Explicit
    2.  
    3. Dim lStart As Long
    4. Dim lEnd As Long
    5. Dim Found As String
    6.  
    7. Private Function FindNext(lStart As Long, lEnd As Long, Found As String) As Boolean
    8.     FindNext = False
    9.     If lStart = 0 Then lStart = -1
    10.     lStart = RTB.Find("*", lStart + 1)
    11.     If lStart < 0 Then Exit Function
    12.     lEnd = InStr(lStart + 1, RTB.Text, vbCrLf)
    13.     Found = Mid(RTB.Text, lStart + 1, lEnd - lStart - 1)
    14.     FindNext = True
    15. End Function
    16.  
    17. Private Sub Command1_Click()
    18.     If Not FindNext(lStart, lEnd, Found) Then
    19.         MsgBox "All Words Found"
    20.     Else
    21.         'do your highlighting here
    22.         MsgBox "Found: " & Found
    23.     End If
    24. End Sub
    25.  
    26. Private Sub Form_Load()
    27.     RTB.SelText = "This is a test" & vbCrLf
    28.     RTB.SelText = "*Find" & vbCrLf
    29.     RTB.SelText = "Don't Find" & vbCrLf
    30.     RTB.SelText = "*Hello" & vbCrLf
    31.     RTB.SelText = "*There" & vbCrLf
    32.     RTB.SelText = "Skip me" & vbCrLf
    33.     RTB.SelText = "*Get" & vbCrLf
    34. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width