473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

RichTextFind methods order of precedence ?

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.

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

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.
Nov 21 '05 #1
3 2353

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

Nov 21 '05 #2


"Larry Lard" wrote:

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 :)


... [snip]
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


Larry, thanks for the response.

I'm a beginner -- please explain what you mean by "correctly combining the
flags". I had found a short snippet in the Help which talked about the
binary (Enum) values of each selection, but nowhere could I find out how to
include the ORed values in the Find statement.

(I also wish someone would tell me how to stop this bulletin board from
putting the html tags in for quotes, ampersands, etc. ... I cannot find
anything on how to properly edit posts so the punctuation marks appear
correctly.)

Nov 21 '05 #3


tcloud wrote:
"Larry Lard" wrote:

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 :)


... [snip]
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


Larry, thanks for the response.

I'm a beginner -- please explain what you mean by "correctly combining the
flags". I had found a short snippet in the Help which talked about the
binary (Enum) values of each selection, but nowhere could I find out how to
include the ORed values in the Find statement.


Because the RichTextBoxFinds type is a Flags type Enum, its values can
be combined. As you have read, each individual value has a single bit
set, so that when the values are combined with Or, multipled flags can
be set:

RichTextBoxFinds.WholeWord = 2 ' 000010
RichTextBoxFinds.MatchCase = 4 ' 000100 in binary
RichTextBoxFinds.NoHighlight = 8 ' 001000
RichTextBoxFinds.Reverse = 16 ' 010000

So for example if we combine WholeWord and MatchCase, we do 2 Or 4
which gives us 6, which is 000110 in binary, and as you see the two
flags we want are set.

As to where to put this combined value, we can use a combined value
wherever a RichTextBoxFinds is required. So for example a Find
operation with just WholeWord set would be:

i = rtxt.Find("word", RichTextBoxFinds.WholeWord)

and if we wanted also to match case we would just say

i = rtxt.Find("word", RichTextBoxFinds.WholeWord Or
RichTextBoxFinds.MatchCase)
It can I suppose appear slightly confusing that we use 'Or' when what
we mean is 'also'; just remember that we are combining binary bits, and
Or is how we do this.

(I also wish someone would tell me how to stop this bulletin board from
putting the html tags in for quotes, ampersands, etc. ... I cannot find
anything on how to properly edit posts so the punctuation marks appear
correctly.)


Sorry, I read this group through Google groups so I can't help with
that...

--
Larry Lard
Replies to group please

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: entoone | last post by:
I know how to use the order by, but wondered if there is an order of precedence in using it. Facts: hcounty is a county that someone puts in a home county in which they live. In the comments...
8
by: der | last post by:
Hello all, I've a question about order of evaluations in expressions that have && and || operators in them. The question is: will the evalution go left-to-right, no matter what -- even if the...
13
by: Ravi Uday | last post by:
Hi, -I have some confusion on the order in which the operators are evaluated. A statement such as 7/9*9+6-4 is evaluated in which order ? -Which of the following is evaluated first: a) && b)...
5
by: mrpermuted | last post by:
Hello, Could someone explain to me why the postfix ++ operator is listed near the top of the operator precedence (above even prefix ++ on my book's chart) but is not evaluated before operators...
8
by: Roshan Mathews | last post by:
According to the precedence rules && has a higher precedence than || and both are 'left to right' associative. So in an expression like ++i || ++j && ++k where i, j, k are 0, -1, 0 (before...
5
by: junky_fellow | last post by:
Hi, I have a very basic doubt about associativity and precedence of operators. I am not a computer science person and may find it quite weird. Consider an expression 4+5*2
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
7
by: pbd22 | last post by:
Hi. I really need some advice on fine-tuning a stored procedure that is the meat of the search logic on my site. Customers are allowed to save searches, which dumps the search logic in a table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.