Change font with IF statement problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Gare

    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((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,
    -2, -2)
    If ThisNumber > 0 then
    fontcolor="#000 000"
    Else
    fontcolor="#fff fff"
    End if
    %>><font color="<%=fontc olor%>"><%=
    FormatNumber((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,
    -2, -2) %></font></td>

    Thanks in advance

    Simon


  • PW

    #2
    Re: Change font with IF statement problem


    "Simon Gare" <sg@simongare.c om> wrote in message
    news:uuhCKKykGH A.1264@TK2MSFTN GP05.phx.gbl...[color=blue]
    > 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((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,
    > -2, -2)
    > If ThisNumber > 0 then
    > fontcolor="#000 000"
    > Else
    > fontcolor="#fff fff"
    > End if
    > %>><font color="<%=fontc olor%>"><%=
    > FormatNumber((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,
    > -2, -2) %></font></td>
    >
    > Thanks in advance
    >
    > Simon
    >
    >[/color]


    How about this instead ...

    <td width="45">
    <%
    ThisNumber =
    FormatNumber((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,
    -2, -2)
    If ThisNumber > 0 then
    response.write ThisNumber
    Else
    response.write "&nbsp"
    End if
    %>
    </td>




    Comment

    • Dave Anderson

      #3
      Re: Change font with IF statement problem

      Simon Gare wrote:[color=blue]
      > 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((D riverPayments.F ields.Item("Car ParkToDriver"). Value),
      > -1, -2, -2, -2)
      > If ThisNumber > 0 then
      > fontcolor="#000 000"
      > Else
      > fontcolor="#fff fff"
      > End if
      > %>><font color="<%=fontc olor%>"><%=
      > FormatNumber((D riverPayments.F ields.Item("Car ParkToDriver"). Value),
      > -1, -2, -2, -2) %></font></td>[/color]

      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.


      Comment

      • Anthony Jones

        #4
        Re: Change font with IF statement problem


        "Simon Gare" <sg@simongare.c om> wrote in message
        news:uuhCKKykGH A.1264@TK2MSFTN GP05.phx.gbl...[color=blue]
        > Hi,
        >
        > trying to hide zero values by changing the colour of the font, problem is[/color]
        it[color=blue]
        > is still printing in a light grey colour? Code below but cant work out[/color]
        where[color=blue]
        > it is going wrong.
        >
        >
        > <td width="45"<%
        > ThisNumber =
        >[/color]
        FormatNumber((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,[color=blue]
        > -2, -2)
        > If ThisNumber > 0 then
        > fontcolor="#000 000"
        > Else
        > fontcolor="#fff fff"
        > End if
        > %>><font color="<%=fontc olor%>"><%=
        >[/color]
        FormatNumber((D riverPayments.F ields.Item("Car ParkToDriver"). Value), -1, -2,[color=blue]
        > -2, -2) %></font></td>
        >
        > Thanks in advance
        >
        > Simon
        >
        >[/color]

        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(Dr iverPayments("C arParkToDriver" ))

        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:25 px"
        class="<%=GetTD Class(DriverPay ments("CarParkT oDriver")%>">
        <%=FormatNumber (DriverPayments ("CarParkToDriv er"))%></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:vis ible}
        td.neg span {visibility:hid den}
        </style>

        and:-

        <td style="width:25 px"
        class="<%=GetTD Class(DriverPay ments("CarParkT oDriver")%>">
        <span><%=Format Number(DriverPa yments("CarPark ToDriver"))%></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 FormatPosNumOnl y(val)
        If val > 0 Then
        FormatPosNumOnl y= FormatNumber(va l)
        Else
        FormatPosNumOnl y= "&nbsp;" ' & n b s p ;
        End If
        End Function
        %>

        and:-

        <td style="width:25 px">
        <%=FormatPosNum Only(DriverPaym ents("CarParkTo Driver"))%>
        </td>


        Anthony.


        Comment

        Working...