Help with script

The following script converts the value from '0' or '1' to 'yes'  or 'no.

I need a script that will do the opposite, so that if the value of a recordset field is say "True" then it is converted to '1'  and if its "False" it is converted to '0'

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>										
function CI_ShowYesNo1(str)				
on error resume next				
if str then		
CI_ShowYesNo1="Yes"		
else		
CI_ShowYesNo1="No"		
end if		
End Function														
</SCRIPT>	

Open in new window


This is my recordset field being displayed:

<%=Request(CI_ShowYesNo1("field3"))%>

Open in new window

LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
Try this. Call it in the same way.
Function CI_Show01Value(str)

    on error resume next

    if lcase(str) = "yes" or lcase(str)="true" or str="1" then
        CI_Show01Value = 1
    else
        CI_Show01Value = 0
    end if

End Function

Open in new window

0
AleksAuthor Commented:
I got:

Microsoft VBScript runtime  error '800a000d'

Type mismatch: 'CI_ShowYesNo1'
0
MlandaTCommented:
How are you calling the function?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

AleksAuthor Commented:
I tried this two ways, type mismatch on both.

<%=Request(CI_ShowYesNo1("field3"))%>

<%= CI_ShowYesNo1(Request("field3"))%>

Open in new window

0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
if your recordset field is a boolean type field, you can use CInt to convert it to a number:

Response.Write CInt( rs("boolField") )

if it's a string value, you may be able to try:

Response.Write CInt( CBool( rs("boolField") ) )
0
MlandaTCommented:
You are just passing the string value, "field3". i wonder if that value is not supposed to be coming from a recordset or user control in which case is should be some like one of the below
<%=CI_ShowYesNo1(Request("field3"))%>
<%=CI_ShowYesNo1(row("field3"))%>

Open in new window

0
AleksAuthor Commented:
That seemed to have worked, the problem is the "True' is being converted to '-1' instead of '1'

This is how I display the values:

visible employer:  

<%=CInt( CBool( Request("field3") ) ) %>

<br/>

Visible contact: 

<%=CInt( CBool( Request("field4") ) ) %>

Open in new window


This is what I see on the screen:

visible employer: 0 
 Visible contact: -1 

Open in new window


It should be '1' not '-1'  .. .any ideas ?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
This is a bit of a hack, but it works:

visible employer:  

<%=Replace( "" & CInt( CBool( Request("field3") ) ) %>

<br/>

Visible contact: 

<%=Replace( "" & CInt( CBool( Request("field4") ) ), "-", "" ) %>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
This worked ... hack and all but it did.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.