Sum of Variables

edited 10:30PM 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 10:30PM
    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 10:30PM
    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 10:30PM
    See a test report template in attach
  • edited 10:30PM
    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