p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   "If or" not working (http://p2p.wrox.com/showthread.php?t=66586)

crabjoe March 12th, 2008 03:08 PM

"If or" not working
 
When I do:

<%If x <> "a" then
response.write "HELLO"
End If%>


Or

<%If x <> "b" then
response.write "HELLO"
End If%>


It runs fine, but if I do:

<%If x <> "a" or x <> "b" then
response.write "HELLO"
End If%>


The script runs, but it runs as if I didn't put "a" or "b" into my form.

Can someone tell me why this is happening?

Thanks!


dparsons March 12th, 2008 03:39 PM

I think you are misunderstanding the logic of the OR operator.

If x gets populated with 'a'
x <> "a" will evaluate to false and processing continues onto the other side of the OR operator
x <> "b" will evaluate to true which causes your response statement to execute.

If x gets populated with 'b'
x <> "a" evaluates to true so the other side of the OR operator is not evaluated and your response statement is executed.

With the OR statement, only one side of the OR needs to evaluate to true for the entire evauation to be true.  

So if you want x to not equal either a or b use the AND operator:
If x <> "a" and x <> "b" then 'do stuff


hth


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========

crabjoe March 12th, 2008 04:15 PM

That's a great explanation and it works!

I was originally going to try "and" but I couldn't see the logic behind it. Now with your explanation, it makes sense.

Thanks!!


dparsons March 12th, 2008 06:03 PM

No problem, glad it worked out for you.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========


All times are GMT -4. The time now is 11:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.