Change font with IF statement problem

Discussion in 'ASP General' started by Simon Gare, Jun 18, 2006.

  1. Simon Gare

    Simon Gare Guest

    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("CarParkToDriver").Value), -1, -2,
    -2, -2)
    If ThisNumber > 0 then
    fontcolor="#000000"
    Else
    fontcolor="#ffffff"
    End if
    %>><font color="<%=fontcolor%>"><%=
    FormatNumber((DriverPayments.Fields.Item("CarParkToDriver").Value), -1, -2,
    -2, -2) %></font></td>

    Thanks in advance

    Simon
    Simon Gare, Jun 18, 2006
    #1
    1. Advertising

  2. Simon Gare

    PW Guest

    "Simon Gare" <> wrote in message
    news:...
    > 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("CarParkToDriver").Value), -1, -2,
    > -2, -2)
    > If ThisNumber > 0 then
    > fontcolor="#000000"
    > Else
    > fontcolor="#ffffff"
    > End if
    > %>><font color="<%=fontcolor%>"><%=
    > FormatNumber((DriverPayments.Fields.Item("CarParkToDriver").Value), -1, -2,
    > -2, -2) %></font></td>
    >
    > Thanks in advance
    >
    > Simon
    >
    >



    How about this instead ...

    <td width="45">
    <%
    ThisNumber =
    FormatNumber((DriverPayments.Fields.Item("CarParkToDriver").Value), -1, -2,
    -2, -2)
    If ThisNumber > 0 then
    response.write ThisNumber
    Else
    response.write "&nbsp"
    End if
    %>
    </td>
    PW, Jun 19, 2006
    #2
    1. Advertising

  3. "Simon Gare" <> wrote in message
    news:...
    > 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("CarParkToDriver").Value), -1, -2,
    > -2, -2)
    > If ThisNumber > 0 then
    > fontcolor="#000000"
    > Else
    > fontcolor="#ffffff"
    > End if
    > %>><font color="<%=fontcolor%>"><%=
    >

    FormatNumber((DriverPayments.Fields.Item("CarParkToDriver").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("CarParkToDriver")%>">
    <%=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("CarParkToDriver")%>">
    <span><%=FormatNumber(DriverPayments("CarParkToDriver"))%></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("CarParkToDriver"))%>
    </td>


    Anthony.
    Anthony Jones, Jun 19, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Hungus

    Font class, external font files question

    Karl Hungus, Feb 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    511
    Karl Hungus
    Feb 4, 2004
  2. =?Utf-8?B?Tmlja3k=?=
    Replies:
    2
    Views:
    691
    Matt Berther
    Feb 20, 2005
  3. Michael Glavitsch
    Replies:
    1
    Views:
    741
    Roedy Green
    Jul 15, 2003
  4. Nick Spinel
    Replies:
    0
    Views:
    916
    Nick Spinel
    Jul 25, 2003
  5. mttc
    Replies:
    2
    Views:
    2,363
    Roedy Green
    Jul 3, 2009
Loading...

Share This Page