somar stringGrid Valores?
ola pesoal estou tetando somar valor dentro de um stringGrid mas nao to conseguindo o comando é:
var
soma, i, j: integer;
matriz: array[1..4,1..4]of integer;
begin
{Transfere do stringGrid para a matriz}
for i:=0 to StringGrid1.ColCount do
for j:=0 to StringGrid1.RowCount do
matriz[(i+1),(j+1)] := StrToInt(StringGrid1.Cells[i][j]);
{Calcula a soma}
soma := 0;
for i:=1 to 4 do
for j:=1 to 4 do
soma := soma + matriz[i,j];
{exibe a soma}
Edit1.Text := IntToStr(soma);
end;
e esta dando erro nesta linha
matriz[(i+1),(j+1)] := StrToInt(StringGrid1.Cells[i][j]);
o q estou fazendo de errado?
var
soma, i, j: integer;
matriz: array[1..4,1..4]of integer;
begin
{Transfere do stringGrid para a matriz}
for i:=0 to StringGrid1.ColCount do
for j:=0 to StringGrid1.RowCount do
matriz[(i+1),(j+1)] := StrToInt(StringGrid1.Cells[i][j]);
{Calcula a soma}
soma := 0;
for i:=1 to 4 do
for j:=1 to 4 do
soma := soma + matriz[i,j];
{exibe a soma}
Edit1.Text := IntToStr(soma);
end;
e esta dando erro nesta linha
matriz[(i+1),(j+1)] := StrToInt(StringGrid1.Cells[i][j]);
o q estou fazendo de errado?
Keliniciante
Curtidas 0
Respostas
Edilcimar
19/04/2006
1) A stringgrid começa em zero, mas se ela tiver uma coluna ou linha com o nome da coluna ou o nome da linha, então vc estará tentando somar algo que não é numérico
2) Aqui StringGrid1.ColCount teria que ser stringgrid1.colcount -1
3) Aqui StringGrid1.RowCount também rowdcount -1
2) Aqui StringGrid1.ColCount teria que ser stringgrid1.colcount -1
3) Aqui StringGrid1.RowCount também rowdcount -1
GOSTEI 0