Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2005, 06:45 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to iloveoatmeal
Default Conditional IF statement

I have an .asp page, which displays an article from the database based on a queryString value, (/news/articleDetails.asp?articleID=1). On the left hand side of the page is a menu, which lists all the articles in the database. I want to italicize (<I></I>) the current article to let the user know which article they are currently reading.

<%articleRequested = Request.QueryString("articleID")%>

<%If articleID = articleRequested Then%>

<i><span class="regText"><%=articleDate%></span> - <a href="/news/articleDetails.asp?articleID=<%=articleID%>">
<%=articleTitle%></a></i><br><br>

<%Else%>

<span class="regText"><%=articleDate%></span> - <a href="/news/articleDetails.asp?articleID=<%=articleID%>">
<%=articleTitle%></a><br><br>

<%End IF%>

Everything works fine with:

<%If articleID = "1" Then%>

Can you do this with an IF statement?

Thanks.
 
Old July 20th, 2005, 07:05 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;Can you do this with an IF statement?
can you do what with an if statement?

Wind is your friend
Matt
 
Old July 20th, 2005, 07:22 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to iloveoatmeal
Default

My conditional statement fails to italicize the record where articleID is equal to the Request.QueryString variable.

<%articleRequested = Request.QueryString("articleID")

If articleID = articleRequested Then
"write record with italics"
Else
"write record without italics"
End IF
%>

However, if the statement is written:

<% If articleID = "1" Then ... it works properly writing the first article title in italics and writting every other record without italics.

How do I write the IF statement to use the value being passed thru the querystring?

Thank you.

I forgot to write that it also works with:

Dim number
number = 1

If articleID = number Then ...
 
Old July 20th, 2005, 07:52 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Ahhh I see. looks like you are comparing one data type to another usesome functions aroung your values:

cInt(trim(articleID)) = cInt(trim(articleRequested))
or
cStr(trim(articleID)) = cStr(trim(articleRequested))

You need to determine if the values are strings or integers:
function 1 = IsNumeric(expression)
Returns a Boolean value indicating whether an expression can be evaluated as a number.

function 2 = TypeName(varname)
Returns a string that provides Variant subtype information about a variable.

function 3 = CStr(expression)
Returns an expression that has been converted to a Variant of subtype String.

basicly you need to check/convert the values you are comparing to the same data types, then it will work









Wind is your friend
Matt
 
Old July 20th, 2005, 08:09 PM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to iloveoatmeal
Default

Matt,

Thank you for your help and the tutorial. Works beautifully.

Chris
 
Old July 20th, 2005, 08:33 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

no worries mate. The way you have acieved you objective is a little verbose, it could be done a bit smarter:

Lets say our articles are in a record set called articles. I assume these are dynamicly generated? - if so I would:

if not articles.EoF then
   do until articles.EoF
      if cInt(trim(articleID)) = cInt(trim(articleRequested)) then response.write "<i>" end if%>
      <span class="regText"><%=articleDate%></span> - <a href="/news/articleDetails.asp?articleID=<%=articleID%>"><%=ar ticleTitle%></a>
<% if cInt(trim(articleID)) = cInt(trim(articleRequested)) then response.write "</i>" end if%>
      <br><br>
<% articles.moveNext
   loop
else
   response.write "no articles found"
end if
%>

Wind is your friend
Matt




Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with conditional sql statement MarkGT Classic ASP Basics 11 May 6th, 2008 08:41 PM
conditional IF roy_mm Reporting Services 0 October 30th, 2006 07:52 AM
Conditional adding spencer.clark XSLT 1 July 28th, 2005 01:19 PM
Datagrid Conditional ~Bean~ ASP.NET 1.0 and 1.1 Basics 3 July 27th, 2005 12:40 AM
conditional statement based on attribute value dancbishop XSLT 2 November 7th, 2003 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.