tcloud wrote:
Is there a rule for the order of methods in the RichTextFind method?
Through experimentation I found an order of the methods when doing reverse
searches.
My experiments produce different results :)
Specifically, when searching reverse, with matching case and for whole
words, the statement must be in this order to work correctly:
-- RichTextBoxFinds.Reverse.MatchCase.WholeWord
When I first saw this, I thought that you must be running with Option
Strict off, because I didn't believe that this was valid syntax. So I
tried it, and lo and behold it compiled! It turns out that although
(for example) RichTextBoxFinds.WholeWord prints as an integer in debug
mode, and claims to be of type Integer in the Watch and Locals windows,
it's actually (as revealed by Typename()) of type RichTextBoxFinds,
which is why it's legal to chain together enum values like this.
Semantically however, only the last in the chain is relevant. That is
to say,
RichTextBoxFinds.WholeWord.NoHighlight.None.MatchC ase.WholeWord = _
RichTextBoxFinds.WholeWord
(they are both 2)
I thought each option was ORed together and their order wasn't important,
and I can find nothing in the Help or any of my references about this.
As the documentation says,
options
A bitwise combination of the RichTextBoxFinds values.
so yes, you Or them together and order is not important.
My testing: Create a form, put a RichTextBox and a Button on it. Put
this code in the Click event handler of the button:
Dim r As RichTextBox = RichTextBox1
Dim i As Integer
r.Text = "The quick BROWN brown fox jumped over the lazy
browner dog Rover."
i = r.Find("over", RichTextBoxFinds.WholeWord Or
RichTextBoxFinds.Reverse)
MsgBox("Find 'over' with Whole Word, Reverse: " & i)
i = r.Find("over", RichTextBoxFinds.Reverse)
MsgBox("Find 'over' with Reverse: " & i)
i = r.Find("over", RichTextBoxFinds.WholeWord.Reverse)
MsgBox("Find 'over' with Whole Word, Reverse CHAINED: " & i)
'same as just Reverse
i = r.Find("brown", RichTextBoxFinds.MatchCase Or
RichTextBoxFinds.Reverse Or RichTextBoxFinds.WholeWord)
MsgBox("Find 'brown' with MatchCase, Reverse, Whole Word: " &
i)
i = r.Find("brown", RichTextBoxFinds.MatchCase)
MsgBox("Find 'brown' with MatchCase: " & i)
i = r.Find("brown", RichTextBoxFinds.Reverse)
MsgBox("Find 'brown' with Reverse: " & i)
i = r.Find("brown", RichTextBoxFinds.WholeWord)
MsgBox("Find 'brown' with Whole Word: " & i)
i = r.Find("brown",
RichTextBoxFinds.MatchCase.Reverse.WholeWord)
MsgBox("Find 'brown' with MatchCase, Reverse, Whole Word
CHAINED: " & i)
'same as just Whole Word
In each case using chained enum values you will find the result is
equal to that obtained with just the last in the chain, and different
from that obtained by correctly combining the flags.
--
Larry Lard
Replies to group please