and...or.....( )

1. Member
Join Date
Dec 1969
Posts
35

## and...or.....( )

I am confused with the usage of "and", "or" and "( )"....<BR><BR>I have three questions on Form 1 (page 1), Q1, Q2and Q3. And depends on the answers to Q1 and Q2, respondent gets asked either Q3 or Q4 on page 2. <BR><BR>If they answer 1-5 for Q1 AND (8-10 for Q2 or 8-10 for Q3), then they are asked Q3. <BR><BR>If they answer 6-10 for Q1 AND (1-7 for Q2 or 1-7 for Q3), then they are asked Q4.<BR><BR>How should i write the asp page? Should i write: <BR>If (q1 &#060; 6) and (q2 &#062;=8 or q3 &#062;=8) Then<BR>response.write Q3<BR>Else<BR>Response.write Q4<BR><BR>Or should i write:<BR>If (q1 &#060;6)and (q2 &#062;=8) or (q3 &#062;=8) Then <BR>Response.write Q3<BR>Else<BR>Response.write Q4<BR>??????<BR>I don&#039;t quite sure how to use "Or", "and" and "()" Is there a thumb of rule for the logic?<BR><BR>Tks

2. Senior Member
Join Date
Dec 1969
Posts
96,118

You put the parens in this sentence:<BR><BR>If they answer 1-5 for Q1 AND (8-10 for Q2 or 8-10 for Q3), then they are asked Q3.<BR><BR>So of course you should put the same parens in the VBS version of the condition!<BR><BR>************<BR><BR>But what you don&#039;t show is what happens if...<BR>If they answer 1-5 for Q1 AND (1-7 FOR Q2 AND anything for Q3), then ...???...<BR><BR>or what happens if...<BR><BR>If they answer 1-5 for Q1 AND (1-7 FOR Q2 OR 1-7 for Q3), then ...???...<BR><BR><BR><BR>

3. Member
Join Date
Dec 1969
Posts
35

um....didn&#039;t think of that. Thank you for reminding me that there are other combinations.<BR><BR>So in other words, it&#039;s just like math? calculating values within ( ) first? Any other rules?<BR><BR>Tks!

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Operator precedence...

...is generally what you would expect. Watch out for unary operators.<BR><BR>http://msdn.microsoft.com/library/en-us/script56/html/vsgrpoperatorprecedence.asp<BR><BR>Note that this clearly shows that<BR><BR>A OR B AND C OR D <BR><BR>would be evaluated as if you had written:<BR><BR>A OR ( B AND C ) OR D<BR><BR>when probably you meant to do<BR><BR>(A OR B) AND (C OR D)<BR><BR>Just do what all C/C++/Pascal/Fortran programmers have done for the last 35 or so years: Put in parentheses when you don&#039;t remember the rules, meaning about 90% of the time. &#060;grin/&#062;<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•