Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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 ...
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
  #6 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:05 AM.


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