Calculation Error in Crystal Report Fomula

2019-06-08 06:15发布

问题:

I have 2 decimal fields: GrossSalary and Deductions. In the report, I created a formula field named NetSalary, which is:

If Not IsNull({SalaryDetails.GrossAmount}) Then
 {SalaryDetails.GrossAmount} - {SalaryDetails.Deduction}

When data is available the report runs correctly, but if not I get the following error

A number, currency amount,date,time, or date-time is required here.
Details:errorKind
Error in File tempxxxxxxxxx.rpt:
Error in formula NetAmount:
'If Not IsNull({SalaryDetails.GrossAmount}) Then
'
A number,currency amount,date,time, or date-time is required here.
Details:errorKind

How can I fix this?

回答1:

Crystal Reports will throw this error if it believes it is working with a value that is not a number. Crystal has many conversion functions like (CDBL, CSTR, etc) and also data check functions (IsNull, IsNumeric, etc) that you can use.

In your particular case, converting the values to a DBL (CDBL({field}) solves your problem after Crystal checks for null values or blanks.



回答2:

The CDBL or IsNumeric function is fine working e.g :

{@Total} / 100 * CDBL({tblinvdetail.disc}). In this formula, disc is the discount column of tblinvdetail table. We assume that disc column also accept null values. To Avoide this error the CDBL or IsNumeric function convert null to 0 value. You should precautionally apply cdbl or IsNumeric fucntion always in any formula in Crystal Report to avoid this kind of error. Use IsNumeric Function if there the value of output has no floating points other wise CDBL function. You can also use IsNull Function to determine null value e.g:

if IsNull({tblinvdetail.disc}) then "0" else {@Total} / 100 * {tblinvdetail.disc}

===================================================================== Munawar Shah AFridi (MCSD.net)