Registriert seit: 31. Mär 2004
Ort: Frankfurt am Main
1.511 Beiträge
Delphi 7 Architect
|
Re: stringgrid addieren
18. Dez 2004, 23:01
Delphi-Quellcode:
procedure TForm1.Button7Click(Sender: TObject);
var
i, y, x: integer;
sum, m1, m2: real;
nr, s, sMyExpression: string;
begin
for y := 1 to 22 do
begin
sum := 0;
for i := 1 to 12 do
begin
if STringGrid1.Cells[i, y] <> '' then
begin
nr := StringGrid1.Cells[i, y];
x := pos('*', nr);
if x > 0 then
begin
m1 := strtofloat(copy(nr, 1, x - 1));
m2 := strtofloat(copy(nr, x + 1, length(nr) - x));
sum := sum + (m1 * m2);
end;
x := pos('+', nr);
if x > 0 then
begin
m1 := strtofloat(copy(nr, 1, x - 1));
m2 := strtofloat(copy(nr, x + 1, length(nr) - x));
sum := sum + m1 + m2;
end
{ ... das weglassen!
else
begin
nr := StringGrid1.Cells[i, y];
nr := nr;
sum := sum + strtofloat(nr);
end;
}
sMyExpression := FloatToStr(sum);
stringgrid1.Cells[13, y] := sMyExpression;
end;
end;
end;
end;
|
|
Zitat
|