怎样对stringgrid的同列分段进行计算就是把stringgrid的某一列的数据根据不同的条件进行分别的计算比如一列数据,数据为质量数,每餐的食物种类不固定,可多可少,现在求早饭、午饭、晚饭的每餐吃的质量数
               
               早饭   牛奶    100
               早饭   面包    100
               ...
               早饭   米饭    50
               午饭   米饭    200
               ...
               午饭   蔬菜    150
               晚饭   米饭    200
               ...
               晚饭   肉      200
               晚饭   蔬菜    100  一列质量总数我已经会算,但分别计算怎样计算呢
下面是一列总的质量数的,已经实现
 vSum:=0;
  for I := 0 to StringGrid1.RowCount - 1 do
    begin
    vSum := vSum + StrToFloatDef(StringGrid1.Cells[1, I], 0);  //统计列
    end;
但分别计算早、午、晚的质量怎样计算呢

解决方案 »

  1.   

    for I := 0 to StringGrid1.RowCount - 1 do
        begin
          if StringGrid1.Cells[0, I]='早饭' then  
            vSum := vSum + StrToFloatDef(StringGrid1.Cells[1, I], 0);  //统计列
        end;
      

  2.   

    for I := 0 to StringGrid1.RowCount - 1 do
    begin
     if StringGrid1.Cells[0, I]='早饭' then  
        vSum1:= vSum1+ StrToFloatDef(StringGrid1.Cells[2,I], 0);  //统计列
     if StringGrid1.Cells[0, I]='午饭' then  
        vSum2= vSum1+ StrToFloatDef(StringGrid1.Cells[2,I], 0);  //统计列
     if StringGrid1.Cells[0, I]='晚饭' then  
        vSum3 vSum1+ StrToFloatDef(StringGrid1.Cells[2,I], 0);  //统计列
    end;
      

  3.   

    to d983074:
       哈哈