1
I have a Stringgrid1 that I fill in the data and from that I calculate the total and the average. In image 1, I demonstrate working correctly. However I may not want to put a number in one of the cells, which causes image error 2.
The code I’m using:
procedure TForm2.Calcular(Sender: TObject);
begin
SaveStringGrid(StringGrid1, 'c:\temp.txt');
end;
procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName);
var
f: TextFile;
i, k, sum: Integer;
med: EXTENDED;
begin
with StringGrid do
begin
for i := 1 to RowCount-1 do
begin
sum := 0;
med := 0;
for k := 1 to ColCount-3 do
begin
sum :=sum + strtoint(Cells [k, i]);
med := sum / k;
Cells [ColCount -2, i] := inttostr(sum);
Cells [ColCount -1, i] := FloatToStr(med);
end;
end;
en