Results 1 to 3 of 3

Thread: [RESOLVED] find and color text red in a richtextbox each time the find button is clicked

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] find and color text red in a richtextbox each time the find button is clicked

    Code:
    Private Sub cmdFind_Click()
    Dim str As String
    Dim Start As Integer
    Dim Length As Integer
    str = txtFind
    Length = Len(str)
    Start = rtfBills.Find(str, , , rtfWholeWord)
    With rtfBills
    .SelStart = Start
    .SelLength = Length
    .SelColor = vbRed
    End With
    This works fine for finding the first occurrence of a word, but need it modified to find the next occurrence of the word with each button click
    How to do this ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] find and color text red in a richtextbox each time the find button is

    Code:
    Private Sub cmdFind_Click()
        Dim strFind As String
    
        strFind = txtFind
    
        With rtfBills
            If LenB(.SelText) Then .SelStart = .SelStart + .SelLength
    
            On Error GoTo 1
           .SelStart = rtfBills.Find(strFind, .SelStart, , rtfWholeWord)
            On Error GoTo 0
    
           .SelLength = Len(strFind)
           .SelColor = vbRed
        End With
    
        Exit Sub
    
    1   If MsgBox("End of search scope has been reached. Continue from the beginning?", vbYesNo Or vbQuestion) = vbYes Then
            rtfBills.SelStart = 0&
            Resume
        End If
    End Sub
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: [RESOLVED] find and color text red in a richtextbox each time the find button is

    Thanks Bonnie West Idid this:
    Code:
    Private Sub cmdFind_Click()
        Dim NewStart As Integer
        Dim str As String
        Static Start As Integer
            Dim Length As Integer
            str = Me.txtFind
            Length = Len(str)
            Start = rtfBills.Find(str, Start, , rtfWholeWord)
        If Start <> -1 Then
            With rtfBills
            .SelStart = Start
            .SelLength = Length
            .SelColor = vbRed
            miNuSearchResults = miNuSearchResults + 1' for reset
            Start = Start + Length
            End With
         Else
            MsgBox "Not found"
       End If
    End Sub
    Last edited by isnoend07; Apr 6th, 2015 at 11:36 AM. Reason: more to add
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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