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

Checking for Null values

Status
Not open for further replies.

tjcusick

Programmer
Dec 26, 2006
134
US
Is it necessary to check for a null value if you are reading the value from a field in as a Float?
Code:
fcurrCS  := qryBOPDetailCREDIT_SCORE.AsFloat;
I've tested it and when ever the field is null in the table the variable comes back as a zero.

What would be the correct programming answer?

Ideas/suggestions?

Tom C
 
Questions:
Do you _need_ to know whether it's null? (what's wrong with it being 0?)
or do you try to avoid possible exceptions? (Answ.: No, it returns 0 so there's no 'danger')

HTH
TonHu
 
The "correct" answer is that "null has no value", where "zero" is a value.

If field = null then //it hasn't been filled.

If field = 0 then //it's been filled as zero.

A Null field.AsFloat will always return 0.

A Null numeric field.AsString will always return ''.

A zero filled numeric field.AsString will always return '0'.

Those all look like differences to me! :)

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top