Solved

If Then Else Syntax Question

Posted on 2006-07-11
4
881 Views
Last Modified: 2012-05-05
I can't seem to get the syntax right.  I am populating from a DB recordset.  What I'd like to achieve is if either the individual recordset column is blank or the recordset itself is "broken" or "missing" then in its place would be: "No Record" rather than the page throwing an error.  Here's what I've been playing with:

<%
Dim rsHeat
Dim rsHeat_cmd
Dim rsHeat_numRows

Set rsHeat_cmd = Server.CreateObject ("ADODB.Command")
rsHeat_cmd.ActiveConnection = MM_heat_STRING
rsHeat_cmd.CommandText = "SELECT * FROM display"
rsHeat_cmd.Prepared = true

Set rsHeat = rsHeat_cmd.Execute
rsHeat_numRows = 0
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<% If (rsHeat.Fields.Item("Heat").Value) = "" Then
     If (rsHeat_total = 0) Then %>
         No Record
         <% Else  %>
<%=(rsHeat.Fields.Item("Heat").Value)%>
  <% End If  
End If%>

</body>
</html>
<%
rsHeat.Close()
Set rsHeat = Nothing
%>
0
Comment
Question by:TCCIRM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 50 total points
ID: 17083909
TCCIRM,

It looks like you are using vbscript and ASP.  The parenthesis are not needed around the condition in the If statement.  Also, why are you doing the second If statement?  Do you want it to use OR?  The code below may work better for you.  I will assume that you want No Record to print if the value is blank or the total is 0.

<% If rsHeat.Fields.Item("Heat").Value = "" OR rsHeat_total = 0 Then
%>
         No Record
         <% Else  %>
<%= rsHeat.Fields.Item("Heat").Value%>
  <% End If  
End If%>

Let me know if you have any questions.

b0lsc0tt
0
 
LVL 96

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 50 total points
ID: 17083911
You've probably got a null in the value - null doesn't equal ""

You check for a null like this:

If IsNull(rsHeat.Fields.Item("Heat").Value) = True Then
0
 

Author Comment

by:TCCIRM
ID: 17084107
Using a combination of both:

<% If IsNull(rsHeat.Fields.Item("Heat").Value) = True OR rsHeat_total = 0 Then %>
         No Record
         <% Else  %>
<%= rsHeat.Fields.Item("Heat").Value%>
<%  
End If%>

However........ when the DB record not "null" and the recordset is not "0" then it should populate from whatever is in the "Heat" field.  It does not.  It writes "No Record" to the page.  
0
 

Author Comment

by:TCCIRM
ID: 17084271
I think my "recordset total" statement is wrong.  If I break the recordset I get an error.  Let me play some more.  Thanks.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question