| Author |
Topic Search Topic Options
|
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
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
|
|
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
Posted: 20 February 2005 at 12:33pm |
|
It's better not to use the ASP blocks in that way (reference to original code)
|
 |
dj air
Senior Member
Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
|
Post Options
Thanks(0)
Quote Reply
Posted: 20 February 2005 at 12:49pm |
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
|
 |
Bluefrog
Senior Member
Joined: 23 October 2002
Location: Korea, South
Status: Offline
Points: 1701
|
Post Options
Thanks(0)
Quote Reply
Posted: 20 February 2005 at 4:34pm |
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.
|
|
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 1:19am |
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).
|
|
|
 |