Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function To Replace Integer with Text

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
In an MS SQL table, I have a number of fields with the value of 0 or 1 (or sometimes Null). I want to present these on screen as "No" and "Yes" and have used some simple conditionals to do it. But it occured to me that maybe it could be more easily done with a simple function. Where ever there is call to write one of those fields, for example (if the function were called "rewrite"):

<%=rs(&quot;Elevator&quot;)%>

which would give the value of 0 or 1, it could call the function something like:

<%=rewrite(rs(&quot;Elevator&quot;))%>

which would replace the 0 or 1 with No or Yes.

Problem is, I don't know where to begin since I've never written a function before. Can someone help? Thanks! Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Function FormatNumber( vNumber )
Dim sTemp
Dim sString
sTemp = vNumber
If Not IsNull(sTemp) Then
IF sTemp = 1 then sString = &quot;YES&quot;
IF sTemp = 0 then sString = &quot;NO&quot;
End if
FormatNumber = sString
End Function
 
This may be a bit quicker:

Code:
<%if rs(&quot;elevator&quot;)=0 then response.write(&quot;no&quot;) else response.write(&quot;yes&quot;) endif %>

Then you won't need to mess with a function.

But if you did want to

Code:
<%=rewrite(rs(&quot;elevator&quot;))%>

to display and then put this in your page (somewhere sensible is good enough)

Code:
<% function returnval(inval)
      if inval = 0 then
         returnval = &quot;no&quot;
      else
         returnval = &quot;yes&quot;
      endif
   End function %>
Derren
[Mediocre talent - spread really thin]
 
Just a tip:

<%if rs(&quot;elevator&quot;)=0 then response.write(&quot;no&quot;) else response.write(&quot;yes&quot;)%>

If you have an If stament and a response.write with or without and else... on one line you don't need End if.
 
Thanks to both of you! I think either one of these will work equally well and was exactly what I needed.

Derren, the reason I don't want to use a conditional is that there is a lot more to it than my simplified example. The values become part of a series of form tags so a conditional was a bit too combersome, especially since the same thing needs to be done in a number of places. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top