Dividing values in Report

Alex_de_KockAlex_de_Kock Bloemfontein, Free State, South Africa
edited 9:23AM in FastReport 4.0
Hallo

I am not a expert in programming, so please excuse me if i'm asking dumb questions! :-)

I need some assistance with diving 2 values from my database, to get the desired value, but it gives me the following error:

"Invalid floating point operation".

My current expression looks as follows

[<SalesSummary."stk_on_hand">/<SalesSummary."NettSales">]


Please help
Thank you

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 9:23AM
    use braces around the fields.
    [((<SalesSummary."stk_on_hand">) / (<SalesSummary."NettSales">))]
  • Alex_de_KockAlex_de_Kock Bloemfontein, Free State, South Africa
    edited 9:23AM
    gordk wrote: »
    use braces around the fields.
    [((<SalesSummary."stk_on_hand">) / (<SalesSummary."NettSales">))]

    Its still giving the same error. When I replace the divide "/" with "+" or"-", it works fine.

    Any advice?
  • edited 9:23AM
    Try to use calculated filed in your query if FR doesn't accept your expression within a MemoView.
    In my example you'll find both ways - a calculated field and an expression inside a MemoView.
    Both with succes >
    SELECT p.*, (cost / onhand) as MyResult                                                                           
      FROM parts p
     where onhand > 0
       and partno < 2000                                                 
     order by partno
    

    Mick
  • Alex_de_KockAlex_de_Kock Bloemfontein, Free State, South Africa
    edited 9:23AM
    Thank you all

    I sorted the query as follows:

    IIF(<SalesSummary."DEPT_CODE"> = '01',(<SalesSummary."stk_on_hand">/<SalesSummary."nettsales">)*4.33,0)

    I Think as the error said "Floating point", it was trying to calculate over and over for my 20 different stock departments, as I didn't specify which department to draw information from.

    Thus setting the Department as a constant, the query could resolve.

    Thank you very much [img]style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> Alex[/img]
  • edited 9:23AM
    I do not think that change you've made has an influence on FR calculation inside a MemoView.
    When the MemoView is on a band then its inside calculation is made just once for each apperance of the band.
    You can prove it by setting where clause
    where DEPT_CODE = '01'
    in your former solutiuon without IIF function.

    Try to test new another solution using OnBeforePrint event for this MemoView, like below:

    Contents of MemoView [MyVariable]
    var MyVariable :real;
    
    procedure Memo1OnBeforePrint(Sender: TfrxComponent);
    begin
      MyVariable := <SalesSummary."stk_on_hand">/<SalesSummary."nettsales">;
    end;
    

    Mick
  • Alex_de_KockAlex_de_Kock Bloemfontein, Free State, South Africa
    edited 9:23AM
    Thank you Mick

    I will look into that, as I'm not so comfortable with writing code yet - have very limited knowledge of it.
    Meanwhile sorted it out with that iff statement and repeating it in the Memo view for each department.

    Alex
  • edited 9:23AM
    Alex,
    wrote:
    ... as I'm not so comfortable with writing code yet ...
    Your yet is the main word in your post [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Pay attention you already DO program using FR script - but you do it inside the MemoView. IIF function is a part of FR script. Yes it may take several hours for you to have no fear while using FR script. But after that you'll have a new tool[/img][img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Start with some easy steps like[/img]
    var
      MyNumber :int;
    
    procedure Memo1OnBeforePrint(Sender: TfrxComponent);
    begin
      MyNumber := 100 * YearOf( DATE);
    end;
    

    and put text [MyNumber] inside Memo1 (alltogether with square brackets).
    Good luck [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Mick[/img]

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.