Solved

If Then Else Syntax Question

Posted on 2006-07-11
4
873 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
  • 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 95

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WSDL Soap Error 12 244
Auto Complete Using JQuery 5 71
SEO friendly way to have two domains on website 9 80
WCAG audit tools 1 52
When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now