473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Change font with IF statement problem

Hi,

trying to hide zero values by changing the colour of the font, problem is it
is still printing in a light grey colour? Code below but cant work out where
it is going wrong.
<td width="45"<%
ThisNumber =
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2,
-2, -2)
If ThisNumber > 0 then
fontcolor="#000000"
Else
fontcolor="#ffffff"
End if
%>><font color="<%=fontcolor%>"><%=
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2,
-2, -2) %></font></td>

Thanks in advance

Simon
Jun 18 '06 #1
3 2132
PW

"Simon Gare" <sg@simongare.com> wrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
Hi,

trying to hide zero values by changing the colour of the font, problem is
it
is still printing in a light grey colour? Code below but cant work out
where
it is going wrong.
<td width="45"<%
ThisNumber =
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2,
-2, -2)
If ThisNumber > 0 then
fontcolor="#000000"
Else
fontcolor="#ffffff"
End if
%>><font color="<%=fontcolor%>"><%=
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2,
-2, -2) %></font></td>

Thanks in advance

Simon

How about this instead ...

<td width="45">
<%
ThisNumber =
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2,
-2, -2)
If ThisNumber > 0 then
response.write ThisNumber
Else
response.write "&nbsp"
End if
%>
</td>


Jun 18 '06 #2
Simon Gare wrote:
trying to hide zero values by changing the colour of the font,
problem is it is still printing in a light grey colour? Code below
but cant work out where it is going wrong.

<td width="45"<%
ThisNumber =
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value),
-1, -2, -2, -2)
If ThisNumber > 0 then
fontcolor="#000000"
Else
fontcolor="#ffffff"
End if
%>><font color="<%=fontcolor%>"><%=
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value),
-1, -2, -2, -2) %></font></td>


I see a number of things going wrong here. For starters, neither #000000 nor
#ffffff is grey, unless you consider black or white shades of grey. Tell us
which value is delivered in the response stream, not the color you perceive.
[View Source] is your best friend. Use it.

Next, comparing a string to a number is fraught with peril. FormatNumber
returns a string. 0 is a number. Is the string "0.00" supposed to be equal
to numeric zero? It is not.

Lastly, you go through the trouble of formatting your number twice -- once
for comparison, again for display. Why not simply display the number
conditionally instead of coloring it conditionally?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 19 '06 #3

"Simon Gare" <sg@simongare.com> wrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
Hi,

trying to hide zero values by changing the colour of the font, problem is it is still printing in a light grey colour? Code below but cant work out where it is going wrong.
<td width="45"<%
ThisNumber =
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2, -2, -2)
If ThisNumber > 0 then
fontcolor="#000000"
Else
fontcolor="#ffffff"
End if
%>><font color="<%=fontcolor%>"><%=
FormatNumber((DriverPayments.Fields.Item("CarParkT oDriver").Value), -1, -2, -2, -2) %></font></td>

Thanks in advance

Simon


Lets take a look a FormatNumber. -2 is the default for the parameters to
which you are supplying it as is the -1. So lets stop doing that. It's a
fair bet the DriverPayments is an ADO recordset hence this all becomes:-

FormatNumber(DriverPayments("CarParkToDriver"))

You only need the format in the output not in the test variable. In fact
it's debatable whether you need a seperate variable at all.

Rather then mucking about with an additional font element why not modify the
style of the TD. In fact rather than mucking about with a style on a TD why
not use a class.

Also placing this sort of logic in line with HTML output makes things
difficult to read so use a function.

The result:-

In a block of server script at the top of the page

<%
Function GetTDClass(val)
If val > 0 Then
GetTDClass = "pos"
Else
GetTDClass = "neg"
End If
End Function
%>

In the <head> of the page:-

<style>
td.pos {color:black}
td.neg {color:white}
</style>

Now in your recordset loop:-

<td style="width:25px"
class="<%=GetTDClass(DriverPayments("CarParkToDriv er")%>">
<%=FormatNumber(DriverPayments("CarParkToDriver")) %></td>
Since it's likely that you are attempting to hide the 0 or negative values
by using white on white this is probably not the best approach. If at some
point you wanted a different background color say a light blue pastel or
some such, these characters would become visible. There are conditions
where having the value in the source output (although not currently visible)
is a useful. Use:-

<style>
td.pos span {visibility:visible}
td.neg span {visibility:hidden}
</style>

and:-

<td style="width:25px"
class="<%=GetTDClass(DriverPayments("CarParkToDriv er")%>">
<span><%=FormatNumber(DriverPayments("CarParkToDri ver"))%></span></td>

OTH if you don't need to the 0 or negative number on the client then PW's
solution of just sending &nbsp; is a good one, there are no need for styles.
Applying the function approach though:-

<%
Function FormatPosNumOnly(val)
If val > 0 Then
FormatPosNumOnly= FormatNumber(val)
Else
FormatPosNumOnly= "&nbsp;" ' & n b s p ;
End If
End Function
%>

and:-

<td style="width:25px">
<%=FormatPosNumOnly(DriverPayments("CarParkToDrive r"))%>
</td>
Anthony.
Jun 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: S.W. Rasmussen | last post by:
A trivial (?) question: does anyone know how to change the shape of the cursor in a RichTextBox control from the normal vertical line to an underscore?
3
by: Mike Barnard | last post by:
Hi all, newbie here. Odd sounding subject but I can't describe it any better. I'm trying to teach myself a little about CSS. In a test site (not published) I am trying to use CSS to make...
3
by: Steve Long | last post by:
I hope this isn't too stupid of a question but I'm looking for a way to change an item in a listview control when the mouse moves over it. I'd like to change its color and underline it for a...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
4
by: Ross Presser | last post by:
I'm feeling very stupid about this ... pdf2html (http://pdf2html.sourceforge.net) is an app that reads a PDF and can generate HTML or XML; in my case I'm using the XML. The PDF I'm working with...
2
by: Geethu03 | last post by:
Hello My PHP code is <?php $headers .='From: support@epcindex.com'; $link = mysql_connect("localhost", "username", "pwd") or die ("Error connecting to mysql:"); ...
1
by: roshina | last post by:
Hi Iam facing a problem in my project, developing a web site for online shopping in ASP on windows XP using IIS server. All the validations are ok but the new password is not upadated in the data...
7
by: moondaddy | last post by:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a mouse over event. how can I do this? -- moondaddy@noemail.noemail
5
by: _Who | last post by:
I spent all day yesterday trying different things. Something has happened so I can't change font size. I have a table and in the first cell I have only text. I tried using the cell's Style...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.