Calculation Error in Crystal Report Fomula

老子叫甜甜 提交于 2019-12-10 11:43:16

问题


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)



来源:https://stackoverflow.com/questions/13747204/calculation-error-in-crystal-report-fomula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!