Sum of Variables

edited 2:38PM in FastReport 4.0
How to add or get sum of variables within report designer NOT run time or script
I???m trying to use sysmemo
I tried
[SUM(<var1> , <var2>)]
But didn???t work


Thanks

Comments

  • edited 2:38PM
    SUM() is an agregate function and you can use it only within any summary band and its events.
    Have a look at demos - how to use agregate functions.
    If - as you write - you need to add two VARIABLES then try such a construction:
    var MyVar1, MyVar2 :real;                                                        
    
    procedure DialogPage1OnShow(Sender: TfrxComponent);
    begin
      Report.Variables[ 'var1'] := 123;
      Report.Variables[ 'var2'] := 877;
      MyVar1 := 0.123;
      MyVar2 := 0.555;                                      
    end;
    
    procedure BitBtn1OnClick(Sender: TfrxComponent);
    begin
      ShowMessage( Report.Variables[ 'var1'] + Report.Variables[ 'var2']);      
      ShowMessage( MyVar1 + MyVar2);      
    end;
    

    Mick
  • edited 2:38PM
    Mick.pl wrote: »
    SUM() is an agregate function and you can use it only within any summary band and its events.
    Have a look at demos - how to use agregate functions.
    If - as you write - you need to add two VARIABLES then try such a construction:
    var MyVar1, MyVar2 :real;                                                        
    
    procedure DialogPage1OnShow(Sender: TfrxComponent);
    begin
      Report.Variables[ 'var1'] := 123;
      Report.Variables[ 'var2'] := 877;
      MyVar1 := 0.123;
      MyVar2 := 0.555;                                      
    end;
    
    procedure BitBtn1OnClick(Sender: TfrxComponent);
    begin
      ShowMessage( Report.Variables[ 'var1'] + Report.Variables[ 'var2']);      
      ShowMessage( MyVar1 + MyVar2);      
    end;
    

    Mick


    Thank you
    I couldn't make works

    Memo1.Text:= floattostr(strtofloat(Report.Variables) + strtofloat( Report.Variables));


    I'm geeting error, if I remove strtofloat, then I get string values like "12""3" insteade 15

    Thanks again
  • gpigpi
    edited 2:38PM
    See a test report template in attach
  • edited 2:38PM
    If one uses
    wrote:
    Report.Variables[ 'var1'] := '12';
    Report.Variables[ 'var2'] := '3';
    it works fine.
    But if one uses
    wrote:
    Report.Variables[ 'var1'] := '12.5';
    Report.Variables[ 'var2'] := '3.3';
    we get an error that nash mentioned.

    My suggestion to nash is: attach an example of your code you use to set initial values of var1 and var2.
    Without knowing that is difficult to find a real source of error in your script:
    wrote:
    Memo1.Text:= floattostr(strtofloat(Report.Variables) + strtofloat( Report.Variables));

    Mick

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.