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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Format a Number in ASP, even if NULL value 1

Status
Not open for further replies.

Cheryl3D

Programmer
Mar 26, 2002
116
US
Hi:

I am having trouble with formatting a number field that has some null or blank values within the column. I'm using ASP in Dreamweaver MX and I have a field called 'Manpower_sum'. When I try to open an asp page for a record that contains a blank or null value in the 'Manpower_sum' field, I receive the following error message:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'FormatNumber'


I am using the FormatNumber function for the line of code that is blowing up, when the field contains a null value.

My syntax for the code that keeps generating the error is:

<input name="Manpower" type="text" id="Manpower" value="<%= FormatNumber( rsGetAnnexData.Fields.Item("Manpower_sum").Value , 4, -2, -2, -1) %>">

What is the correct syntax if I want to adjust the statement above for null values, where if the field is null for the record I want it to leave it blank " " or default to a value of zero represented by the format 0.0000?

How do I incorporate the IsNull function into the statement above?

I tried doing something like:
<input name="Manpower" type="text" id="Manpower" value="<%=
If IsNull(FormatNumber( rsGetAnnexData.Fields.Item%("Manpower_sum").Value , 4, -2, -2, -1),0)%>">

But I don't think that is it.

Any help would be greatly appreciated.

Cheryl3D





 
How about:
Code:
<input name="Manpower" type="text" id="Manpower" value="<%
   If Not isNull(rsGetAnnexData.Fields.Item("Manpower_sum").Value) Then _
      Response.Write FormatNumber( rsGetAnnexData.Fields.Item("Manpower_sum").Value , 4, -2, -2, -1) 
   %>">

it makes it longer, but also ensures the initial value (which is what is causing the FormatNumber function to blow up) is not null. I could probably squeeze it all onto one line but it seemed a litle easier on the eyes this way.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Hello.

Why not test the recordset/field value prior to calling the function?

If isNull() Then
<input ....>
Else
<input ....FormatNumber(...)>
End If




Forti
 
That would kinda be what I was aiming for there man :)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Hi Tarwn:

Works like a charm!!! Thank you very much for your help.

Thanks forti as well.

-Cheryl3D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top