...

View Full Version : IF Statment question, i think?



startbar
07-14-2004, 05:20 PM
hi, i have this course list which shows course info etc..

in one of the sections my code is
The course is currently set to run at <%=objRS("Venue")%> - so its html text and then the venue from the database.

my problem is that if a courses venue is undecided the venue is written as TBC. (to be confirmed) and so the sentence The course is currently set to run at TBC - doesnt make sense.

can i have it so if <%=objRS("Venue")%> = TBC show some other text - for example 'The venue is TBC'

any ideas? thanks

angst
07-14-2004, 05:46 PM
not quite sure what u mean,,

well if TBC is really in the data feild then just:


<%
if objRS("Venue") = "TBC" then
response.write "some text"
else
response.write "some other text"
end if
%>

startbar
07-14-2004, 07:19 PM
thanks, thats excellent - but how can you add the venue detail into the code?

i tried..

<%
if objRS("Venue") = "TBC" then
response.write "Sorry this venue is currently set to objRS("Venue")"
else
response.write "This venue is due to run at objRS("Venue")"
end if
%>

but it didnt work! thanks

ASPwiz
07-14-2004, 08:26 PM
Use this:-


<%
if objRS("Venue") = "TBC" then
response.write "Sorry this venue is currently set to " & objRS("Venue")
else
response.write "This venue is due to run at " & objRS("Venue")
end if
%>

Rob

startbar
07-14-2004, 08:28 PM
thanks!

very helpful ! :thumbsup:

startbar
07-14-2004, 08:41 PM
what about a date?

how could i make it so if <%=objRS("Date")%> was 'Todays date' it would say today instead of the date...

thanks

angst
07-14-2004, 08:52 PM
well, how are you storing the date in the db?
it's it in a date feild and what format?

u could do:

If objRS("Date")=DATE() Then
response.write "Today"
else
response.write "something else"
end if

startbar
07-15-2004, 05:02 PM
can you add a link in this code?

If objRS("Date")=DATE() Then
response.write "Today"
else
response.write "something else <a href="something.asp" class="more">click</a>
end if

??

thanks

angst
07-15-2004, 10:03 PM
yup,
just make sure u include a closing quote on the responce.write
and double quotes on =""something.asp""


If objRS("Date")=DATE() Then
response.write "Today"
else
response.write "something else <a href=""something.asp"" class=""more"">click</a>"

startbar
07-18-2004, 02:52 PM
if i have a value 'strSearch' how do i use this in a IF statement?

so far i got :

<%
if strSearch = "%" then
response.write "You have chosen to view all results."
else
response.write "Your search for " & "strSearch" returned " & "iRecordCount" Companies."
end if
%>

the one that says 'You have chosen to view all results.' works but the other shows 'strSearch' instead of the actual word that was searched for.

any ideas?

thanks

glenngv
07-19-2004, 03:56 AM
Don't put it in quotes if it's a variable.


response.write "Your search for "
& strSearch
& " returned "
& iRecordCount
& " Companies."

It should be in one line, I put it in multiple lines for readability. It seems you're confused on concatenating strings with variables.

startbar
07-23-2004, 02:57 PM
whats wrong with this!!


<%
if objRS("Filename") = "" then
response.write "<img src=""images/nologo.gif"">"
else
response.write "<img src=""images/" & objRS("Filename").gif""">"
end if
%>

wont work!!

startbar
07-23-2004, 03:02 PM
Help please!

<%=objRS("Filename")%> is the entry for the persons filename. so i use

<img src="images/<%=objRS("Filename")%>.gif" border="0"> to show them.

however when the person has no image how do i get it to show a nologo.gif

i tried with this if statement but doesnt work!!


<%
if objRS("Filename") = "" then
response.write "<img src=""images/nologo.gif"">"
else
response.write "<img src=""images/companylogos/" & objRS("Filename") & ".gif"">"
end if
%>

glenngv
07-26-2004, 02:17 AM
Try this:


<%
dim fileName
fileName = objRS("Filename")
response.write "filename:" & fileName & "<br />" 'debug
if fileName = "" or IsNull(fileName) then
response.write "<img src=""images/nologo.gif"">"
else
response.write "<img src=""images/companylogos/" & fileName & ".gif"">"
end if
%>

startbar
07-26-2004, 10:47 AM
how do i get it so it doesnt say the filename as well?

thanks, tho that is excellent

glenngv
07-26-2004, 11:48 AM
how do i get it so it doesnt say the filename as well?

thanks, tho that is excellent
What do you mean? :confused:
Do you mean this line?

response.write "filename:" & fileName & "<br />" 'debug

I just put it for debugging purposes as the comment says. Of course, you need to remove it in the actual code.

startbar
09-26-2004, 12:10 PM
if i had a section like this


<td width="50%" valign="top">
<font class="companytext"><B>Website</B><BR>Please visit our website on <a class="linksbig" href="http://<%=objRS("URL")%>"><%=objRS("URL")%></a>

</td></tr></table>

how would i make it so if the person didnt have a website it would say 'sorry no website' and if they did it would show the '<B>Website</B><BR>Please visit our website on...'

thanks

BuddhaMan
09-26-2004, 09:13 PM
Many ways to skin that cat, but I'd do it like this:

Pass the URL record to a function which determines if it's null or not (assuming you store a null if no website is entered elsewhere). If it's null, pass back the "sorry" statement, else pass back the text and URL.

I'd make sure it's a well formed URL on entry into the database/form. The way you coded it make me believe it's stored as "www.blah.com" and not http://www.blah.com"


<%
Private Function Website(strURL)
Dim TempWebSite

If IsNull strURL Then
TempWebSite = "Sorry, no website available."
Else
TempWebSite = "Please visit our website on <a class=""linksbig"""_
" href="http://" & strURL & ">" & strURL & "</a>"
End If

Website = TempWebSite
End Function
%>

<td width="50%" valign="top">
<font class="companytext"><B>Website</b><br /><%Website(objRS("URL"))%>

</td></tr></table>

startbar
09-26-2004, 10:26 PM
thanks, ill try that

glenngv
09-27-2004, 01:29 AM
<td width="50%" valign="top">
<font class="companytext"><B>Website</b><br /><%Website(objRS("URL"))%>

</td></tr></table>[/code]
There should be an = there.
<%=Website(objRS("URL"))%>

And you should also check for empty url.


If IsNull(strURL) or strURL="" Then

BuddhaMan
09-27-2004, 02:20 AM
Thanx for the backup. I normally output all my HTML in Response.Write statements so I'm not used to doing it that way. :)

I actually wrote my answer the first time using a subroutine and outputting all the HTML via response.write.....then my browser decided to die for no reason. :\

startbar
09-29-2004, 05:31 PM
i get a HTTP 500 internal server error...


<%@ Language=VBScript %>

<!--#include file="includes/adovbs.inc"-->
<%

dim objConn, strCon, objRS, strSQL
Set objConn = Server.CreateObject("ADODB.Connection")

strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\exhibitors\exhibitors.mdb"

objConn.connectionstring = strCon
objConn.Open
Set objRS = Server.CreateObject("ADODB.Recordset")
ON ERROR RESUME NEXT

Dim pageView, strNewsText

pageView=Request.Querystring("view")
%>

<html>
<head>
<link rel="stylesheet" href="/css/text.css" type="text/css">
</head>

<!--#include virtual="/header.asp"-->

<%if pageView="" THEN

strSQL="SELECT * FROM exlist WHERE Sold=1 ORDER BY Name ASC"

objRS.Open strSQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF NOT objRS.EOF THEN
'objRS.Filter=objRS("Status")=1
%>

<title>asiashow.co.uk : exhibitors list</title>

<font class="titles"><BR><img src="/images/bullet.gif"> EXHIBITORS LIST</font><BR><font class="newstext">View our current exhibitors. Click the 'Show Presence' tab for more information.<BR><BR>

<table cellpadding="3" cellspacing="0" width="100%" style="border: 0px solid #971C10;">

<tr>
<td><font class="text"><b>Exhibitor Name</b></td>
<td><font class="text"><b>Date Added</b></td>
<td><font class="text"><b>Show Presence</b></td>
</tr>

<%
DO WHILE NOT objRS.EOF%>
<%if intRowColor = 0 Then
Response.Write "<TR bgcolor=""#F6EFF9"" onMouseOver=""this.bgColor = '#f5f4db'"" onMouseOut =""this.bgColor = '#F6EFF9'"">"
intRowColor = 1
Else
Response.Write "<TR bgcolor=""#ffffff"" onMouseOver=""this.bgColor = '#f5f4db'"" onMouseOut =""this.bgColor = '#FFFFFF'"">"
intRowColor = 0
End if%>

<td><a class="links" href="viewall.asp?view=Display&ID=<%=objRS("ID")%>"><%=objRS("Company")%></a></td>
<td><a class="links" href="viewall.asp?view=Display&ID=<%=objRS("ID")%>"><%=objRS("Date")%></a></td>
<td><a class="links" href="viewall.asp?view=Display&ID=<%=objRS("ID")%>"><%=objRS("Presence")%></a></td>


</tr>
<%
objRS.MoveNext
Loop
objRS.Close
%>
</table>
<%ELSE%>
<p>There are currently no articles in the News Database or there are no live articles to display, please use the admin section to upload them.

<p></p>
<%END IF%>
<%END IF%>

<%IF pageView="Display" THEN

strSQL="SELECT * FROM exlist WHERE ID="&Request.QueryString("ID")

objRS.Open strSQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText%>

<title>asiashow.co.uk : exhibitors list : <%=objRS("Company")%></title>

<font class="comptitle"><BR><%=objRS("Company")%><BR><BR><img src="/images/logoorpic.gif"><BR><BR></font>

<font class="companytext">Owned by: <%=objRS("Name")%><BR>
<font class="companytext">We are located at <a href="/floorplan/" class="linksbig"><%=objRS("Presence")%></a> (click for floorplan position)<BR><BR>

<font class="companytext"><B>Description</B><BR>
<%=objRS("Description")%><BR><BR>

<font class="companytext"><B>Our Products:</B><BR><%=objRS("Products")%><BR><BR>

<font class="companytext"><B>Details:</B><BR>
We are using a <%=objRS("Type")%> (<%=objRS("Dimensions")%>m, <%=objRS("Area")%>sm)
<BR><BR>

<table width="100%" cellpadding="0">
<tr>
<td width="50%">
<font class="companytext"><B>Contact Us</B><BR>
<%=objRS("Address")%>
<%=objRS("Street")%><BR>
<%=objRS("Town")%><BR>
<%=objRS("County")%><BR>
<%=objRS("Country")%><BR>
<%=objRS("Postcode")%><BR>
<%=objRS("Phone")%><BR><BR>
Email us:<BR><a class="linksbig" href="mailto:<%=objRS("Email")%>"><%=objRS("Email")%></a>


</td>




<%
Private Function Website(strURL)
Dim TempWebSite

If IsNull strURL or strURL="" Then
TempWebSite = "Sorry, no website available."
Else
TempWebSite = "Please visit our website on <a class=""linksbig"""_
" href="http://" & strURL & ">" & strURL & "</a>"
End If

Website = TempWebSite
End Function
%>

<td width="50%" valign="top">
<font class="companytext"><B>Website</b><br /><%=Website(objRS("URL"))%>

</td></tr></table>




<%END IF%>

<!--#include virtual="/footer.asp"-->



</body>
</html>

startbar
09-29-2004, 06:59 PM
Microsoft VBScript compilation error '800a03f9'

Expected 'Then'

/exhibitors/viewall.asp, line 144

If IsNull strURL or strURL="" Then
----------^


getting this now... help please!!!!

Roy Sinclair
09-29-2004, 08:56 PM
If IsNull(strURL) or strURL="" Then


A simpler way to check is one I often use:



if Len(strURL) < 1 then


The length will be 0 if it's null or if it's an empty string.

startbar
09-29-2004, 09:01 PM
yes but it doesnt work - im getting a 500 internal server error.. any ideas?

Roy Sinclair
09-29-2004, 09:28 PM
500 Internal Server Error doesn't tell me a thing. Doesn't it tell you what line of your code it doesn't like?

startbar
09-29-2004, 09:30 PM
no it doesnt.. it says nothing just the error

Roy Sinclair
09-29-2004, 09:48 PM
Short of telling you to get a browser that isn't brain dead, there is a way to get the error message from IE.

In IE's "Tools" menu select "Internet Options", on the "Advanced" tab scroll down to the checkbox labeled "Show friendly HTTP error messages" and clear that checkbox. The label is a lie, what that particular label should say is "Remove all useful information from error messages". Press "Apply" and try your page again, you should get something more than just that silly raw error :) .

startbar
10-09-2004, 12:21 PM
<%
Private Function Website(strURL)
Dim TempWebSite

If strURL="" Then
TempWebSite = "Sorry, no website available."
Else
TempWebSite = "Please visit our website on <a class=""linksbig"" href=""http://" & strURL & "">" & strURL & ""</a>"
End If

Website = TempWebSite
End Function
%>


<font class="companytext"><B>Visit Our Website</b><br /><%=Website(objRS("URL"))%>

i got the page to load with this code but it just says

Visit Our Website
True

??

thanks

Roy Sinclair
10-11-2004, 08:56 PM
You've got a quoting problem that's giving you a logical result instead of a string:



You have:

TempWebSite = "Please visit our website on <a class=""linksbig"" href=""http://" & strURL & "">" & strURL & ""</a>"

It should be:

TempWebSite = "Please visit our website on <a class=""linksbig"" href=""http://" & strURL & """>" & strURL & "</a>"

startbar
10-11-2004, 08:57 PM
thanks, i sorted that already :)

startbar
02-02-2005, 08:05 PM
if i have


<%
if objRS("Trial") = "1" then
response.write "Trial"
else
response.write "Subscription"
end if
%>

to show whether an entry is a trial or subscrition how can i make it so it will only show the 'days left' section for trial users.


<td style="padding: 3px; margin: 0px auto;"><%
dim d, d2, daysLeft
d = objRS("Date")
if not isnull(d) and isdate(d) then
d2 = dateadd("D", 90, d)
daysLeft = datediff("D", Date(), d2)
response.write "" & daysLeft & " days"
else
response.write "Null or invalid date"
end if
%></td>

so IF trial=1 it will show the days left code above but IF trial=0 it will say n/a

THANKS!!

ghell
02-03-2005, 09:34 AM
firsly you should use a boolean value in your database (eg yes/no, true/false, on/off if u are using ms access) then you should say

if objRS("Trial") = true then
'display days left
intDaysLeft = datediff("d", Date(), dateadd("d", 90, CDate(objRS("Date"))))
Response.Write "TRIAL: " & intDaysLeft & " Days Remaining"
else
'display n/a.. is this really needed though, wouldnt it be easier just to not do anythng if its not a trial
Response.Write "N/A"
end if

this is assuming the "Date" field is the start date for the trial and its a 90 day trial, and does not handle null dates in the "Date" field but if they arent on a trial this shouldnt matter as it wont be run

startbar
02-03-2005, 04:45 PM
thanks for that gnell, very helpful as always! just wish i understood as well as you do!

Is there any way i can make the text a different colour, like lets say red when the 'days left' drops below 15?

Thanks

startbar
02-03-2005, 04:51 PM
and how would i make it count upwards from a date, like 3 days since subscription.

Thank You

ghell
02-04-2005, 08:48 AM
to return the time since the start of the subscription you just use another datediff()

between the subscription date and the current date (you could do it the other way round but i think it would return a negative value, theres always the Abs() function to get rid of minuses though)

try this for that and the red thing
If objRS("Trial") = true Then
'display days left
intDaysLeft = DateDiff("d", Date(), dateadd("d", 90, CDate(objRS("Date"))))
intDaysPast = DateDiff("d", CDate(objRS("Date")), Date())
If intDaysLeft <= 15 Then
Response.Write "<span style=""color: #FF0000;"">TRIAL: " & intDaysLeft & " Days Remaining</span>"
Else
Response.Write "TRIAL: " & intDaysLeft & " Days Remaining"
End If
Else
'display n/a.. is this really needed though, wouldnt it be easier just to not do anythng if its not a trial
Response.Write "N/A"
End if



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum