Ver Mensaje Individual
  #1  
Antiguo 05-02-2013
steelha steelha is offline
Miembro
 
Registrado: mar 2012
Posts: 158
Reputación: 13
steelha Va por buen camino
Como hacer para totalizar una columna de un stringgrid por valor

Hola foristas, la siguiente duda es acerca de trabajar con los stringgrid, me piden leer un txt el cual trae una inmencidad de datos, lo cual ya realice. Luego me piden que si puedo dar los datos mas resumidos, es decir, que por numero de autorizacion el cual se guarda en la primera columna. Al implementar este codigo el cual y segun yo no iva a tener ningun tipo de problema me encuentro con que me da error de Out of index justamente al entrar en la parte del codigo en rojo he intentado ver el porque y no he dado con el problema. utilizo Delphi 7, tadvstringgrid de los componentes Devexp.

Código Delphi [-]
procedure TForm1.Button4Click(Sender: TObject);
var
  ruta : string;
  dia  : Word;
  mes  : Word;
  ano  : Word;
  hor  : Word;
  min  : Word;
  sec  : Word;
  mil  : Word;
  i    : Integer;
  romp : string;
  total: Real;
  filaactual : integer;
begin
  DecodeDate(Now,ano,mes,Dia);
  DecodeTime(Now,hor,min,sec,mil);
  ruta := OpenDialog1.InitialDir +'Universal_'+inttostr(Dia)+inttostr(mes)+inttostr(ano)+'_'+inttostr(hor)+inttostr(min)+inttostr(sec  )+'.txt';

  i     := 0;
  total := 0;
  filaactual := 0;
  romp  := '';
  romp  := Trim(DataGrid.Cells[0,2]);
  for i := 1 to (DataGrid.RowCount-1) do
  begin
    DataGrid.Row := i; //Posicionar en 1ra fila a trabajar
    If Trim(DataGrid.cells[0,i]) <> '' then
    begin
      If Trim(DataGrid.cells[0,i]) <> Trim(romp) then
          begin
            filaactual := DataGridagrupado.RowCount;
            DataGridagrupado.Row := filaactual;
            DataGridagrupado.Cells[0,filaactual-1] := DataGrid.Cells[0,i];
            DataGridagrupado.Cells[1,filaactual-1] := DataGrid.Cells[1,i];
            DataGridagrupado.Cells[2,filaactual-1] := FloatToStr(total);
            total := 0;
            total := total + StrToFloat(DataGrid.cells[2,i]);
            romp  := Trim(DataGrid.cells[0,i]);
            DataGridagrupado.AddRow;
          end
      else
          total := total + StrToFloat(DataGrid.cells[2,i]);
    end;
  end;

  DataGridagrupado.SaveToCSV(ruta);
end;
Responder Con Cita