How to manually sum values in DBCrossTab?

edited 1:37AM in FastReport 4.0
Hi, my problem is connected with summimg time in DBCrossTab. I've got an idea, but I don't know how to implement it.

So I have DBCrossTab, let's say it's like that:
RowName   |   Val1   |   Val2   |   Val3   |   Total
--------------------------------------------------------
Row 1       |   1   |   5   |    3   |   9
--------------------------------------------------------
Row 2       |   4   |   3   |   3   |   10


I know that I FastReport gives me ability to sum these values automaticly, but I can't use this ability in my problem. I have to do some operations before summing.

So the question is: how to sum these rows manually?

Comments

  • edited 1:37AM
    OK, I think I managed to do this, but maybe there is a simpler, better way. I did it like that(in FR Script):

    
    var
      rowSecs: integer; //seconds for a row
    
    procedure DBCross1OnPrintCell(Memo: TfrxMemoView; RowIndex, ColumnIndex, CellIndex: Integer; RowValues, ColumnValues, Value: Variant);
    var
      h, m, s, ms: word;
      hStr, mStr: string;                                            
    begin
      if ColumnIndex = DBCross1.ColCount - 1 then //column is total                 
      begin
        h:=rowSecs div 3600; //count hours
        rowSecs:=rowSecs - (3600*h); 
        m:=rowSecs div 60; //count minutes
        s:=rowSecs - (60*m); //and seconds. I don't really need them for now
    
        if h>9 then hStr:=intToStr(h) else hStr:='0'+intToStr(h); //always show (h)hh:mm
        if m>9 then mStr:=intToStr(m) else mStr:='0'+intToStr(m);
        
        Memo.Text:=hStr+':'+mStr;
        rowSecs:=0;
      end else                                                               
      begin              
        if Value<>null then
        begin              
          DecodeTime(Value, h, m, s, ms);
          s:=s+(m*60)+(h*3600);                                            
          rowSecs:=rowSecs + s;
        end;
      end;              
    end;
    
    begin
      rowSecs:=0;                            
    end.
    
    
  • edited January 2010
    I have little another problem

    How to sum values but not all the columns, for example, only 2 and 3 columns.
    Or sum all columns, and then subtract value from 1 column.

    Unfortunately, I do not know where is the column, which I do not want to count. I have to check her name.

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.