find and color text red in a richtextbox each time the find button is clicked

Private Sub cmdFind_Click()
Dim NewStart As Integer
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

Open in new window


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 ?
isnoend2001Asked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
I just saw that you are still using VB6? That should work better for you:

Start = rtfBills.Find(str, Start, , rtfWholeWord)

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
change:
Dim Start As Integer

Open in new window


for
Static Start As Integer

Open in new window


and just before the "end with", add
Start += Length

Open in new window

0
 
isnoend2001Author Commented:
Thanks but it still only finds the first occurrence .
Dim str As String
Static Start As Integer
Dim Length As Integer
str = Me.txtFind
Length = Len(str)
Start = rtfBills.Find(str, , , rtfWholeWord)

With rtfBills
.SelStart = Start
.SelLength = Length
.SelColor = vbRed
Start = Start + Length
End With

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Éric MoreauSenior .Net ConsultantCommented:
You also need to use a different Find overloads:
Start = rtfBills.Find(str, Start, rtfWholeWord)

Open in new window

0
 
isnoend2001Author Commented:
Start = rtfBills.Find(str, Start, rtfWholeWord) where to put that ?
0
 
Éric MoreauSenior .Net ConsultantCommented:
replace line 6 of your last example
0
 
isnoend2001Author Commented:
That produces an error "Invalid property value"
start is -1
0
 
isnoend2001Author Commented:
txtFind contents = HARBOR
rtfBills contents:
6/13/2003 VILLAGE SUPPLIES LTD   ALSIP  IL -24.61
6/17/2003 LEWIS & LEWIS ENTERPR   VENTURA CA -96.09
6/27/2003 HARBOR FREIGHT TOOLS   805 388-2000    CA -58.77
7/7/2003 BUY.COM   WWW.BUY.COM CA -27.84
7/11/2003 THE NEXTREND INC   IRVINE  CA -18.74
7/15/2003 AMAZON.COM  *PAYMENTS   800-201-7575 WA -11.23
7/20/2003 AMAZON.COM  *PAYMENTS   800-201-7575    WA -13.99
7/21/2003 HARBOR FREIGHT TOOLS   805 388-2000    CA -58.77
8/5/2003 AMAZON.COM  *PAYMENTS   800-201-7575    WA -14.48
8/12/2003 BUY.COM   WWW.BUY.COM CA -26.34
8/13/2003 HARBOR FREIGHT TOOLS   805 388-2000    CA -61.81
8/28/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -83.13
8/28/2003 ECAMPUS COM   TEL8595145200 KY -49.83
9/4/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -108.74
10/13/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -56.87
11/7/2003 BUY.COM   WWW.BUY.COM CA -29.17
11/13/2003 HARBOR FREIGHT TOOLS   805 388-2000 CA -23.89
12/15/2003 AMAZON.COM  *SUPERSTOR   AMAZON.COM WA -30.59
0
 
isnoend2001Author Commented:
Thanks Éric Moreau that works
0
 
isnoend2001Author Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for isnoend2001's comment #a40708332

for the following reason:

Thanks Éric Moreau
0
 
Éric MoreauSenior .Net ConsultantCommented:
Why don't you accept my comment as the answer?
0
 
isnoend2001Author Commented:
Thanks thought i did
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.