Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Needs Help With IF Statement
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Needs Help With IF Statement

 Post Reply Post Reply Page  12>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Needs Help With IF Statement
    Posted: 20 February 2005 at 1:57am
I have an IF Statement that I need help with.
 
Here's the code:
 

     <% If IDValue <> 1 and 14 and 15 and 16 then

         %>There are no articles

        

         <%else %>

         <%=Content %>

         <% end if %>

 
I would like for the web page to display "There are no articles" if the IDValue is not equal to 1, 14, 15, and 16. I know that my If Statement is not right. How do I work around the bolded code to make it work correctly? <% If IDValue <> 1 then %><%else %><%=Content %><% end if %><%else %><%=Content %><% end if %>
Misty
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 2:51am
<% If IDValue <> 1 and 14 and 15 and 16 then %> should be:
<% If IDValue <> 1 OR IDValue <> 14 OR IDValue <> 15 OR IDValue <> 16 then %>


Edited by -boRg- - 21 February 2005 at 4:32am
Cristian Banu
Soft 4 web
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 8:59am
If IDValue <> 1 and IDValue <> 14 and IDValue <> 15 and IDValue <> 16 then
Another way is
 
Select Case IDValue
    Case 1 or 14 or 15 or 16
        ~do something~
     Case Else
        ~do something else
End Select
 

Lead me not into temptation... I know the short cut, follow me.
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 12:33pm
It's better not to use the ASP blocks in that way (reference to original code)
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 12:49pm
Originally posted by zaboss zaboss wrote:

<% If IDValue <> 1 and 14 and 15 and 16 then %> should be:
<% If IDValue <> 1 OR IDValue <> 14 OR IDValue <> 15 OR IDValue <> 16 then %>


that wont work. because if its 14 it is allowd from teh first check as its different to 1.

the way to do it is put it in brackets
<% If (IDValue <> 1 OR IDValue <> 14 OR IDValue <> 15 OR IDValue <> 16) then %>
dj air2005-2-20 12:51:2

Edited by
Back to Top
Bluefrog View Drop Down
Senior Member
Senior Member


Joined: 23 October 2002
Location: Korea, South
Status: Offline
Points: 1701
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bluefrog Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 4:34pm
Originally posted by dpyers dpyers wrote:

If IDValue <> 1 and IDValue <> 14 and IDValue <> 15 and IDValue <> 16 then
Another way is
Select Case IDValue
Case 1 or 14 or 15 or 16
~do something~
Case Else
~do something else
End Select

Dpyers is correct above - use AND. Do not use OR. Since the "<>" is evaluated first, if the value is 15, then "IDValue <> 1" will evaluate to true, and the entire expression will be true because of the OR operators.

You could alternatively use:

If IDValue = 1 OR IDValue = 14 OR IDValue = 15 OR IDValue => 16 then


to only display if it is true, which is a much better way to do things. Positive logic is generally better than negative logic.

Also, SELECT CASE is an easier way to do it, and a bit more maintainable if you want to change things later.


Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 6:49pm

Something a little OT.

zaboss's code doesnt show up in IE6, but dj air's quote of it does.
 
Both the code and the quote show up fine in FF.

Lead me not into temptation... I know the short cut, follow me.
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 21 February 2005 at 1:19am
Originally posted by dpyers dpyers wrote:

Something a little OT.

zaboss's code doesnt show up in IE6, but dj air's quote of it does.
Both the code and the quote show up fine in FF.
Well this has nothing to do with ASP, but with HTML arround it. ASP does not interfere with browsers, as the code is executed before the html is sent to browsers. So, there is something in your HTML code that upset IE, although usualy hapends the opposites (code displaz OK in IE, but not in FF).
Cristian Banu
Soft 4 web
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.