 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 28th, 2012, 09:58 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Display True / False for Boolean (-1 or 0)
I need to display a page with True or False instead of the 0 or -1 that is appearing.
I have a switch that either shows a login to be disabled, 0 or -1. (Not sure why it is showing up as "-1" on the page.
Code:
Response.Write "<td class=clsBodyText>" & objRS.Fields("Disabled") & " </td>"
I am using a Sql server 2008 with Classic ASP.
Please let me know if more information is required.
Thanks,
|
|

August 29th, 2012, 12:36 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
If you are getting a value from SQL Server for a bool data type the only values that should be presenting them selves are 1 which is True or 0 which is false, therefore to print True or False on your page a function like this would work for you:
Code:
function ShowTrueFalse(theVal)
if theVal = "1" then
ShowTrueFalse = "True"
else
ShowTrueFalse = "False"
end if
end function
why you are getting -1 I no idea, your should really know this. Im sure you can alter the function above to work for you...
__________________
Wind is your friend
Matt
Last edited by mat41; August 29th, 2012 at 12:37 AM..
Reason: typo in function
|
|

August 29th, 2012, 09:19 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Hey Matt, Thanks for the reply.
I don't have experience using or building with a function. I have been using my text book to help understand the usage but I guess I'm just missing something. There is a column "Disabled" that will show either "0" or "-1" and then I want to put True or False instead.
My page:
Code:
%@ Language=VBScript%>
<% Option Explicit %>
<!-- #include file = "conn.asp" -->
<%
function ShowTrueFalse(theVal)
if theVal = "0" then
ShowTrueFalse = "False"
else
ShowTrueFalse = "True"
end if
end function
%>
<html>
<head>
<title>Acct Enabled</title>
</head>
<body bgcolor="WhiteSmoke">
<table border="0" width='95%' cellspacing="0" cellpadding="1" ID="Table1">
<TR>
<TD align="center" class="clsFieldLabel" colspan="7">
Account Labels </td>"
</tr>
<tr>
<td align="left" class="clsFieldLabel"><u>Server Name</u></td>
<td align="left" class="clsFieldLabel"><u>User ID</u></td>
<td align="left" class="clsFieldLabel"><u>Description</u></td>
<td align="left" class="clsFieldLabel"><u>Disabled</u></td>
<td align="left" class="clsFieldLabel"><u>Locked Out</u></td>
<td align="left" class="clsFieldLabel"><u>Last Login</u></td>
<td align="left" class="clsFieldLabel"><u>User Acct Label</u></td>
</tr>
<%
Dim conn, objConn , objRS, i
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = sConnection
conn.Open
Set objRS = conn.Execute("SELECT SERVER_NAME, User_Id, Description, Disabled, Lockedout, CONVERT(char(10), LastLogin, 101) AS LastLogin FROM Acct")
i=0
While Not objRS.EOF
response.Write "<tr>" 'beginning of row
Response.Write "<td class=clsBodyText>" & objRS.Fields("SERVER_NAME") & " </td>"
Response.Write "<td class=clsBodyText>" & objRS.Fields("User_Id") & " </td>"
Response.Write "<td class=clsBodyText>" & objRS.Fields("Description") & " </td>"
Response.Write "<td class=clsBodyText>" & objRS.Fields("Disabled") & " </td>"
Response.Write "<td class=clsBodyText>" & objRS.Fields("Lockedout") & " </td>"
Response.Write "<td class=clsBodyText>" & objRS.Fields("LastLogin") & " </td></tr>"
i=i+1
objRS.MoveNext
Wend
Response.Write "<td class=clsBodyText>Total Servers:" & i & "</td>"
objRS.Close
Set objRS = Nothing
conn.Close
Set conn = Nothing
Not sure where I am suppose to evaluate each rotation of the disabled switch? I don't use ASP that much so I have a hard time remembering all the steps. I think I need a way to evaluate each passing of the "Disabled" column and then parse it through the Function. So I guess I need to "Dim" the value then compare.
Any guidance would be greatly appreciated.
As far as the 0 or -1, I did find out the Disabled column is a float, which I'm not sure why it's not a bit. Still learning.
Thanks,
|
|

August 29th, 2012, 09:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
which is true and which is false. normally 0 would be false........but since you have a -1 anything is possible
__________________
Wind is your friend
Matt
|
|

August 29th, 2012, 09:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
The question aside to use the function simply do this:
Code:
Response.Write "<td class=clsBodyText>" & ShowTrueFalse(objRS.Fields("Disabled")) & " </td>"
Dont forget to chnage the function because at the moment the function says:
if theVal = "1" then print True
Just change the value surrounded in quotes to what ever you True value is supposed to be which should be either "0" or "-1"
__________________
Wind is your friend
Matt
Last edited by mat41; August 29th, 2012 at 09:36 PM..
|
|

August 30th, 2012, 11:39 AM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Hey Matt,
Thanks for the guidance. I will review how the function needs to be set. Again, the code to update the table is handled by another person and I don't have access. Once I confirm, I'll be able to update the function accordingly.
Take care,
|
|
The Following User Says Thank You to snteran For This Useful Post:
|
mat41 (August 30th, 2012)
|
|

August 30th, 2012, 07:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
No worries.....a bit of a tip If I may. You should answer questions from people who are trying to help you. I did ask:
;;;which is true and which is false. normally 0 would be false........but since you have a -1 anything is possible
if you had answered I would have altered the function so it actually print what it should when it should......
__________________
Wind is your friend
Matt
|
|

August 31st, 2012, 08:39 PM
|
|
Authorized User
|
|
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Hey Matt, sorry about that. I thought it was more of a comment and not a question. "0" does equal false. I have setup the function and it's working great.
Thanks,
|
|

September 2nd, 2012, 06:41 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
No worries, glad it working....
__________________
Wind is your friend
Matt
|
|
 |