Print Page | Close Window

if statement problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4639
Printed Date: 30 March 2026 at 1:12pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: if statement problem
Posted By: simflex
Subject: if statement problem
Date Posted: 31 July 2003 at 8:37am

This should be really easy but ... it isn't working.

status on my db (sql server) has of 0 or 1.

0 for false and 1 for true.

So I am saying if that if the value is 0 then print "Open"

if not, print "Complete"

The value that is being printed is always "Open"

I tried this first:

Dim strStart,strFinal
If strStart = 0 then
  strFinal = " <font color=""#FF0000"">Open</font>"
else
  strFinal = " <font color=""#009900"">Complete</font>"
end if
Response.Write "<font color=""#000000"">" & strFinal& "</font>"

it didn't work.

Then I tried this below:

Dim strStart,strFinal
Do While Not rst.EOF
if strStart = 0 then
  strFinal = " <font color=""#FF0000"">Open</font>"
else
  strFinal = " <font color=""#009900"">Complete</font>"
end if
Response.Write "<font color=""#000000"">" & strFinal& "</font>"
rst.MoveNext

but still getting "Open" as value.

Please tell me what I am doing wrong.

 

 




Replies:
Posted By: michael
Date Posted: 31 July 2003 at 9:20am
Where are you getting the value out of the database? Should it not be something like strStart = rst("Status") to set the value first??

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: simflex
Date Posted: 31 July 2003 at 9:45am

I do have that assignment in my code - strStart = rst("status").

I just missed, for some reason, including that line in my post to this forum.

So yes, that value was already assigned in my code.



Posted By: Flamewave
Date Posted: 31 July 2003 at 10:03am
Try casting the value to an integer: strStart = Int(rst("status"))

-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: simflex
Date Posted: 31 July 2003 at 10:20am

I actually did that; it didn't make any difference in result.



Posted By: ljamal
Date Posted: 31 July 2003 at 4:37pm
Try

If not Cbool(rst("status")) then
strFinal = " <font color=""#FF0000"">Open</font>"
else
strFinal = " <font color=""#009900"">Complete</font>"
end if


-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: simflex
Date Posted: 31 July 2003 at 9:49pm

Nope, that didn't work!

What is so freaking annoying about this is that if I just leave it as rst("status"), it displays the result correctly; that is it displays either True or False but to make the result more meaningful to the user by using that simple if statement has been a nightmare.



Posted By: pmormr
Date Posted: 01 August 2003 at 5:47pm

oh, i think sql server has problems with using 1 and 0 the way your using them. Try using 'y' and 'n' and see what happens...



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: pmormr
Date Posted: 01 August 2003 at 5:48pm
or open and complete...

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: simflex
Date Posted: 01 August 2003 at 8:08pm

ok, to illustrate how frustrating this has been, examine these code segments.

      If CInt(rst("Completed")) = 0 Then
             Response.Write "<font color=""#FF0000"">Open</font>"
        Else
             Response.Write "<font color=""#009900"">Completed</font>"

      End If
     ***********************************

strStart = CInt(rst("status"))

if strStart = 0 then
  strFinal = " <font color=""#FF0000"">Open</font>"
else
  strFinal = " <font color=""#009900"">Complete</font>"
end if
Response.Write "<font color=""#000000"">" & strFinal& "</font>"

The first one works great.

I can't see any difference beween the two, can anyone?



Posted By: b_bonnett
Date Posted: 02 August 2003 at 3:28am

The only difference I see is that you're using CInt(rst("Completed")) in the first one and CInt(rst("status")) in the second.

Blair



-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net