Solved

If Then Else Syntax Question

Posted on 2006-07-11
4
875 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 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