Summing a Memo TfrxMemoView

Hi,

I have a budget style report with a number of columns and the value displayed in the Report field can vary based on the period range selected by the user.

So for each detail the value is calculated using the following statement, in the OnBeforePrint event
var
 aValue : Double;                                               
begin

 aValue := 0;

 if 1 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY01">;
 if 2 in [<Start_Month>.. <End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY02">;
 if 3 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY03">;
 if 4 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY04">;
 if 5 in [<Start_Month>.. <End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY05">;
 if 6 in [<Start_Month>.. <End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY06">;
 if 7 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY07">;
 if 8 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY08">;
 if 9 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY09">;
 if 10 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY10">;
 if 11 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY11">;
 if 12 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY12">;
 if 13 in [<Start_Month>..<End_Month>] then aValue := aValue + <dbAccumBudget."ACTUALLASTQTY13">;
                                                          
 if 14 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY01">;  
 if 15 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY02">;  
 if 16 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY03">;  
 if 17 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY04">;  
 if 18 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY05">;  
 if 19 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY06">;  
 if 20 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY07">;  
 if 21 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY08">;  
 if 22 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY09">;  
 if 23 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY10">;  
 if 24 in [<Start_Month>..<End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY11">;  
 if 25 in [<Start_Month>.. <End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY12">;  
 if 26 in [<Start_Month>.. <End_Month>] then aValue := aValue +<dbAccumBudget."ACTUALQTY13">;  
                            
 Grp2_ActualQty := Grp2_ActualQty + aValue;                                                               

 qtyActual.Memo.Text := FormatFloat( '#,##0.00', aValue );

I was hoping that I could use the SUM() function to sum the values from the object QtyActual and place in to my group Footer and one for Report Total, but can not seem to get a value to return, tried QtyActual.Memo.Text (which I didn't expect to work) and QtyActual.Value

So the only way I can see (at the moment) to get a sub-total is to use a variable that increases the calculate value after each detail line is printed...

i.e.
Grp2_ActualQty := Grp2_ActualQty + aValue

Then in my group footer, I have another field that is sent on the OnBeforePrint event
  TotalG2ActualQty.Memo.Text := FormatFloat( '#,##0.00', grp2_ActualQty );
  grp2_ActualQty := 0;

It works OK, but I have a number of columns to repeat this for, and was wondering if I am missing some very simple and obvious way of using the SUM function on a TfrxMemoView component...

Any simple method, would be much appreciated...

Regards
Simon

PS: Coming from crystal reports where you create a formula, stick it on a report and right click sum, I have become very lazy >

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 6:58AM
    Simon
    Read the user manual on groups and aggregates, aggregates must be used in the correct footer
    also when using variables for intermediate values you may find declaring them at the start of the code page (global to all objects). declaring in side the procedure is local to procedure only
    you can also write common procedures and link them to the event of object or band.
    Don't think about how you did it in crystal.

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.