-
Apr 6th, 2015, 08:42 AM
#1
Thread Starter
PowerPoster
[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
-
Apr 6th, 2015, 10:54 AM
#2
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)
-
Apr 6th, 2015, 11:35 AM
#3
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|