Skip to main content
Inspiring
March 9, 2007
Question

format error when null

  • March 9, 2007
  • 2 replies
  • 262 views
On my .asp page I am formatting values in a table like:

FormatCurrency((rsPartsData.Fields.Item("Act03").Value), 0, -2, -2, -2)

Problem is, when the value is NULL I get an error (because you can't format
NULL, of course). I've tried if/then in the table cell and using coalesce
along with the format - both with no luck.

How can I code it so that if the value is NULL I just display $0 ??


This topic has been closed for replies.

2 replies

Inspiring
March 9, 2007
use the IsNull function to check the value before formatting. IIRC
something like this should work (long time w/o using ASP, i turned coat
to PHP (-;)

If IsNull(rsPartsData.Fields.Item("Act03").Value) Then
Response.Write "$0"
Else
Response.Write
FormatCurrency((rsPartsData.Fields.Item("Act03").Value), 0, -2, -2, -2)
End If


HX wrote:
> On my .asp page I am formatting values in a table like:
>
> FormatCurrency((rsPartsData.Fields.Item("Act03").Value), 0, -2, -2, -2)
>
> Problem is, when the value is NULL I get an error (because you can't format
> NULL, of course). I've tried if/then in the table cell and using coalesce
> along with the format - both with no luck.
>
> How can I code it so that if the value is NULL I just display $0 ??
>
>
Inspiring
March 9, 2007
Found it:

Create a NullToZero function:

function NullToZero(pData)
if len(pData) = 0 then
NullToZero = cdbl(0)
else
on error resume next
pData = cdbl(pData)
if not IsNumeric(pData) then pData = 0
NullToZero = cdbl(pData)
end if
end function

Then use the function in your call to FormatNumber:
<%=formatNumber(NullToZero(ars.Fields("SOLD_AMOUNT")),2)%>


"HX" <mymail@somemail.com> wrote in message
news:esshn9$1s0$1@forums.macromedia.com...
> On my .asp page I am formatting values in a table like:
>
> FormatCurrency((rsPartsData.Fields.Item("Act03").Value), 0, -2, -2, -2)
>
> Problem is, when the value is NULL I get an error (because you can't
> format NULL, of course). I've tried if/then in the table cell and using
> coalesce along with the format - both with no luck.
>
> How can I code it so that if the value is NULL I just display $0 ??
>