Totals - SUM problem

dannidanni Denmark
edited May 2010 in FastReport .NET
Hi

the expression for a total I convert a String to a Decimal.

When the databand I SUM over is empty, I get a conversion exception.

Note: I print the first row if the databand is empty.

Comments

  • edited 6:11AM
    Hello,

    FastReport cannot handle this. It's up to you to convert a string to decimal correctly. You may create own function in the report code that performs the conversion and checks for empty values.
  • dannidanni Denmark
    edited 6:11AM
    It's too about wether the values in the reportobjects are empty. It's if the datasource for a band is emty, not NULL but just en empty list.

    The ToDecimal(object obj) function should and do convert object values to a decimal, BUT it shouldnt be called if the datasource is empty. I have no way to correct this when using the Totals-SUM function as I see it.
  • edited 6:11AM
    Since you are using the PrintIfDataSourceEmpty option of a databand, everything is called as expected.
    Could you make a simple demo for me and send it to tz@fast-report.com? Maybe I misunderstood something...
  • dannidanni Denmark
    edited May 2010
    Hi again.
    I have to take it back - I think.

    My colleague made a copy of a report that has a Total(sum).

    On the copy, the reportobject [Total] was reomved without removing it from the list in the Data window.

    This means that the expression in the list of Totals is validated no matter if it is draged on to the report?

    We fixed it by deleting the Total.
  • edited 6:11AM
    That's true, every total is calculated, no matter if it is actually used in a report object.
  • dannidanni Denmark
    edited 6:11AM
    How do I avoid getting a parsing error when the dataource is empty (for the validated reportobject)?

    in my sum function I try to convert a string to a decimal.

    Somehow I need to check if the databand is empty within my expression?
  • edited 6:11AM
    You may write own script function and use it instead of ToDouble standard function. Something like this:
    private double TryToDouble(string value)
    {
      try
      {
        return ToDouble(value);
      }
      catch
      {
        return 0;
      }
    }
    
  • dannidanni Denmark
    edited 6:11AM
    Ok, Will do that.

    I would think your standard functions had a default return value and used a try/catch?

    >

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.