Print Page | Close Window

Needs Help With IF Statement

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=13900
Printed Date: 30 March 2026 at 1:11pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Needs Help With IF Statement
Posted By: Misty
Subject: Needs Help With IF Statement
Date 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



Replies:
Posted By: zaboss
Date 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 %>


-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: dpyers
Date 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.


Posted By: Gullanian
Date Posted: 20 February 2005 at 12:33pm
It's better not to use the ASP blocks in that way (reference to original code)


Posted By: dj air
Date 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


Posted By: Bluefrog
Date 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.




-------------
http://renegademinds.com/" rel="nofollow - Renegade Minds - Guitar Software http://renegademinds.com/Default.aspx?tabid=65" rel="nofollow - Slow Down Music


Posted By: dpyers
Date 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.


Posted By: zaboss
Date 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
http://www.soft4web.ro - Soft 4 web


Posted By: dpyers
Date Posted: 21 February 2005 at 4:26am
Nothing to do with asp at all, just noting that this code displays the table, but not the code text within it in IE6
<table width="100%" border="0" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
       <td class="text" style="font-family: "Courier New", Courier, mono;"><pre width=100>
<% If IDValue <> 1 OR IDValue <> 14 OR IDValue <> 15 OR IDValue <> 16 then %>
</pre></td>
      </tr>
     </table>


-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: dpyers
Date Posted: 21 February 2005 at 4:32am
As another interesting aside, when I go to edit the post in IE, the rte shows blank lines between the code tags - took out all the data between the code - /code tags but left the linefeeds. When I preview the edited post, the code appears as blanks.

-------------

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net