[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

RichTextBox Won't Find String

Saucer Man

7/10/2011 11:07:00 PM

I'm having problems trying to find a string. I'm using...

Private Sub cmdFind_Click()
lngStartPos1 = txtNewBIOS.Find("<game", 0)
lngEndPos1 = txtNewBIOS.Find("/game", lngStartPos1) + 5

While lngStartPos1 > 0
txtNewBIOS.SelStart = lngStartPos1
txtNewBIOS.SelLength = lngEndPos1
txtNewBIOS.SelBold = True
strString = txtNewBIOS.SelText
lngLength1 = Len(strString)

'Clear selection
txtNewBIOS.SelBold = False
txtNewBIOS.SelStart = 0
txtNewBIOS.SelLength = 0

'Attempt to find the next match
lngStartPos1 = txtNewBIOS.Find("<game", lngStartPos1 + lngLength1)
lngEndPos1 = txtNewBIOS.Find("/game", lngStartPos1) + 5
Wend
End Sub

This works the up to the point where it attempts to find the next match. It
finds the next "<game" correctly but it fails to find the next "/game". I
can tell because when it bolds the selection it continues to bold way past
the "/game". What is wrong here?
--
Thanks.



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
5 Answers

Mike Williams

7/11/2011 9:00:00 AM

0

"Saucer Man" <saucerman@nospam.net> wrote in message
news:ivdba4$233u$1@adenine.netfront.net...

> I'm having problems trying to find a string. I'm using...
> Private Sub cmdFind_Click()
> lngStartPos1 = txtNewBIOS.Find("<game", 0)
> lngEndPos1 = txtNewBIOS.Find("/game", lngStartPos1) + 5
> While lngStartPos1 > 0
> txtNewBIOS.SelStart = lngStartPos1
> txtNewBIOS.SelLength = lngEndPos1
> txtNewBIOS.SelBold = True
> strString = txtNewBIOS.SelText
> lngLength1 = Len(strString)
> 'Clear selection
> txtNewBIOS.SelBold = False
> [rest of code snipped]
> This works the up to the point where it attempts to find the next
> match. It finds the next "<game" correctly but it fails to find the
> next "/game". I can tell because when it bolds the selection it
> continues to bold way past the "/game". What is wrong here?

There are some other problems which you haven't yet mentioned but your main
problem is that you are treating the SelLength property as though it
specifies the end of the selection, whereas of course it specifies its
length. Change that line to:

txtNewBIOS.SelLength = lngEndPos1 - lngStartPos1

Mike



Saucer Man

7/11/2011 9:59:00 PM

0

"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:ivee2j$gse$1@dont-email.me...
> There are some other problems which you haven't yet mentioned but your
> main problem is that you are treating the SelLength property as though it
> specifies the end of the selection, whereas of course it specifies its
> length. Change that line to:
>
> txtNewBIOS.SelLength = lngEndPos1 - lngStartPos1
>
> Mike
>

That works but I also had to change the +5 to +6. Thanks Mike. Can you
tell me what else you see wrong???



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

Mike Williams

7/11/2011 10:38:00 PM

0

"Saucer Man" <saucerman@nospam.net> wrote in message
news:ivfrnv$1div$1@adenine.netfront.net...
> That works but I also had to change the +5 to +6.
> Thanks Mike. Can you tell me what else you see wrong???

Nothing very important, and it depends on what you actually want to achieve.
For example in the code you posted you are getting the string including the
<game and /game tags. If that's what you want then that's okay of course,
otherwsie you need to adjust for the tags. Also, you are setting the
selection's SelBold to true and then almost immediately setting the same
selection's SelBold back to False again, so the bold is not actually seen,
but perhaps that is also what you want?

Mike



Saucer Man

7/12/2011 12:35:00 AM

0

"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message
news:ivftvs$b3o$1@dont-email.me...
> Nothing very important, and it depends on what you actually want to
> achieve. For example in the code you posted you are getting the string
> including the <game and /game tags. If that's what you want then that's
> okay of course, otherwsie you need to adjust for the tags. Also, you are
> setting the selection's SelBold to true and then almost immediately
> setting the same selection's SelBold back to False again, so the bold is
> not actually seen, but perhaps that is also what you want?
>
> Mike

Ahhh... Yes, I wanted the tags in the string. After I find a string, I am
going to search another richtextbox to see if the string is present. If so,
I will delete both of them from the richtextboxes and continue. I'm hoping
to be left with two textboxes showing the differences only. The bold is
only in the code to test so I can see if it is working correctly. Thank
you!

Hopefully I will be able to figure out how to remove the string from the
textboxes when needed.



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

Mike Williams

7/12/2011 8:25:00 AM

0

"Saucer Man" <saucerman@nospam.net> wrote in message
news:ivg4ri$1pid$1@adenine.netfront.net...

> The bold is only in the code to test so I can see if it
> is working correctly. Thank you!

Okay. By the way you'll also need to consider the possibility that the main
string might contain a <game tag without its corresponding /game tag, in
which case your code as it currently stands will produce an error. There are
various ways to fix that but first you'll need to decide what you want to do
in such a circumstance, possibly ignore it completely or report the error to
the user or perhaps return the section to the end of the main string or
whatever.

Mike