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

Code advice; handling nulls

Status
Not open for further replies.

MikeT

IS-IT--Management
Feb 1, 2001
376
US
I pull numbers from a database and do calculations on them in an asp page. These calculations require I check for nulls, which I do by:

Code:
if isnull(rs("Price")) then
   varPrice=0
else
   varPrice=rs("Price")
end if

It seems to me there should be a more elegant way of doing this. I know the number field in the db shouldn't be allowing null values, and I could change it, but I want to keep that as a last resort.

Any suggestions?
 
I'm no expert, but I'd do exactly what you have listed above. Nothing wrong with it in my opinion. Rob
Just my $.02.
 
So, make your own function to handle it for you:

Function CheckValue(onevalue)

If onevalue = null Then onevalue=0
CheckValue=onevalue
End Function

varPrice=CheckValue(rs("Price"))
varNumber=CheckValue(rs("Number"))
'etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top