9 Replies Latest reply on Apr 21, 2009 4:12 PM by comment_1

# Quick calculation question (grouping ands and ors together)

### Title

Quick calculation question (grouping ands and ors together)

### Post

I'm working on a calculation to validate a field:"Cash" or Length ( gPaymentCheckNumber) greaterthanorequalto 4

Is there a way to add an "and" function to only the second part of this equation (I want it to have to be a numerical value).

• ###### 1. Re: Quick calculation question (grouping ands and ors together)

"Cash" OR (length (gPaymentCheckNumber) > 4 AND gPaymentCheckNumber = 5)

The parenthesis improve readability and force  the expression inside the () to be evaluated first.

• ###### 2. Re: Quick calculation question (grouping ands and ors together)

The parentheses are redundant because 'and' is evaluated before 'or'.

BTW, "Cash" will NEVER return true.

• ###### 3. Re: Quick calculation question (grouping ands and ors together)

Redundant as to evaluation order but useful in improving readability. (I don't try to keep every detail of order of precedence rules straight when I can use Parenthesis to be sure :smileywink: )

I assumed that "Cash" was a placeholder for a more complex expression. If not, then good point.

• ###### 4. Re: Quick calculation question (grouping ands and ors together)

Thanks.

• ###### 5. Re: Quick calculation question (grouping ands and ors together)

PhilModJunk wrote:

Redundant as to evaluation order but useful in improving readability.

IMHO, redundant parentheses do the opposite of improving readability. If you want to make it clear what's happening, you can write it as:

test1

or

test2 and test3

PhilModJunk wrote:

I assumed that "Cash" was a placeholder for a more complex expression.

In quotes?!

• ###### 6. Re: Quick calculation question (grouping ands and ors together)

To each their own. IMHO, parenthesis are like using salt in cooking. A little at the right time helps a lot, too much and you've got a problem. In this example, a simple single line expression, the parenthesis eliminate any ambiguity on the part of a person analyzing the expression as to whether OR or AND will evaluate first. I save multi-line expressions for more complex things like a Case function with 5 clauses or such.

As to the "Cash" term, I did say your comment was a good idea didn't I? :smileywink:

I was assuming that the original poster was saying "here's a part of the expression where everything works so I won't bother to post it here..." Of course you may have heard the Joke about what happens when you assume things right?

• ###### 7. Re: Quick calculation question (grouping ands and ors together)

PhilModJunk wrote:

the parenthesis eliminate any ambiguity on the part of a person analyzing the expression

On the contrary. The purpose of parentheses is to change the order of evaluation. Redundant parentheses serve only to confuse. If the order of evaluation remains unchanged, why are there parentheses - says the person analyzing the expression.

• ###### 8. Re: Quick calculation question (grouping ands and ors together)
Not this person, since the order is made obvious by the self same parenthesis :smileywink:
• ###### 9. Re: Quick calculation question (grouping ands and ors together)
Well, if it 's between you and yourself, then it's no concern of mine.