Тема: два цикла
Показать сообщение отдельно
  #6  
Старый 19.08.2008, 07:45
Аватар для artemavd
artemavd artemavd вне форума
Начинающий
 
Регистрация: 05.08.2008
Сообщения: 115
Репутация: 12
По умолчанию Большой код и несколько вопросов)

Вот весь код всей процедуры:
Код:
var
 a:array[0..3] of integer;
 b:array[1..25] of integer;
 i:integer;
begin
 for i:=1 to 25 do
 begin
 //количество оценок в SG3
   SG3.Cells[0,i]:=IntToStr(StrToInt(SG2.Cells[0,i])+
   StrToInt(SG2.Cells[1,i])+StrToInt(SG2.Cells[2,i])+
   StrToInt(SG2.Cells[3,i]));
 //средний бал в SG3
   SG3.Cells[1,i]:=
   FloatToStrF(2*StrToInt(SG2.Cells[0,i])/StrToInt(SG3.Cells[0,i])+
           3*StrToInt(SG2.Cells[1,i])/StrToInt(SG3.Cells[0,i])+
           4*StrToInt(SG2.Cells[2,i])/StrToInt(SG3.Cells[0,i])+
           5*StrToInt(SG2.Cells[3,i])/StrToInt(SG3.Cells[0,i]),ffFixed,1,1);
 //Качество успеваемости в SG3
   SG3.Cells[2,i]:=
   FloatToStrF(Trunc((StrToInt(SG2.Cells[2,i])+StrToInt(SG2.Cells[3,i]))*100)
              /StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
 //Успеваемость в SG3
   SG3.Cells[3,i]:=
   FloatToStrF(100-Trunc(StrToInt(SG2.Cells[0,i])*100)/StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
 //Обученность в SG3
   SG3.Cells[4,i]:=
   FloatToStrF(Trunc((2*StrToInt(SG2.Cells[0,i])+3*StrToInt(SG2.Cells[1,i])+
           4*StrToInt(SG2.Cells[2,i])+5*StrToInt(SG2.Cells[3,i]))*20)
           /StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
 //Четвертная оценка в SG3
   SG3.Cells[5,i]:=
   FloatToStrF(Trunc(2*StrToInt(SG2.Cells[0,i])+3*StrToInt(SG2.Cells[1,i])+
           4*StrToInt(SG2.Cells[2,i])+5*StrToInt(SG2.Cells[3,i]))
           /StrToInt(SG3.Cells[0,i]),ffFixed,0,0);

  SG2.Cells[0,26]:=
      FloatToStr(StrToInt(SG2.Cells[0,1])+StrToInt(SG2.Cells[0,2])+
      StrToInt(SG2.Cells[0,3])+StrToInt(SG2.Cells[0,4])+
      StrToInt(SG2.Cells[0,5])+StrToInt(SG2.Cells[0,6])+
      StrToInt(SG2.Cells[0,7])+StrToInt(SG2.Cells[0,8])+
      StrToInt(SG2.Cells[0,9])+StrToInt(SG2.Cells[0,10])+
      StrToInt(SG2.Cells[0,11])+StrToInt(SG2.Cells[0,12])+
      StrToInt(SG2.Cells[0,13])+StrToInt(SG2.Cells[0,14])+
      StrToInt(SG2.Cells[0,15])+StrToInt(SG2.Cells[0,16])+
      StrToInt(SG2.Cells[0,17])+StrToInt(SG2.Cells[0,18])+
      StrToInt(SG2.Cells[0,19])+StrToInt(SG2.Cells[0,20])+
      StrToInt(SG2.Cells[0,21])+StrToInt(SG2.Cells[0,22])+
      StrToInt(SG2.Cells[0,23])+StrToInt(SG2.Cells[0,24])+
      StrToInt(SG2.Cells[0,25]));

   SG2.Cells[1,26]:=
      FloatToStr(StrToInt(SG2.Cells[1,1])+StrToInt(SG2.Cells[1,2])+
      StrToInt(SG2.Cells[1,3])+StrToInt(SG2.Cells[1,4])+
      StrToInt(SG2.Cells[1,5])+StrToInt(SG2.Cells[1,6])+
      StrToInt(SG2.Cells[1,7])+StrToInt(SG2.Cells[1,8])+
      StrToInt(SG2.Cells[1,9])+StrToInt(SG2.Cells[1,10])+
      StrToInt(SG2.Cells[1,11])+StrToInt(SG2.Cells[1,12])+
      StrToInt(SG2.Cells[1,13])+StrToInt(SG2.Cells[1,14])+
      StrToInt(SG2.Cells[1,15])+StrToInt(SG2.Cells[1,16])+
      StrToInt(SG2.Cells[1,17])+StrToInt(SG2.Cells[1,18])+
      StrToInt(SG2.Cells[1,19])+StrToInt(SG2.Cells[1,20])+
      StrToInt(SG2.Cells[1,21])+StrToInt(SG2.Cells[1,22])+
      StrToInt(SG2.Cells[1,23])+StrToInt(SG2.Cells[1,24])+
      StrToInt(SG2.Cells[1,25]));

   SG2.Cells[2,26]:=
      FloatToStr(StrToInt(SG2.Cells[2,1])+StrToInt(SG2.Cells[2,2])+
      StrToInt(SG2.Cells[2,3])+StrToInt(SG2.Cells[2,4])+
      StrToInt(SG2.Cells[2,5])+StrToInt(SG2.Cells[2,6])+
      StrToInt(SG2.Cells[2,7])+StrToInt(SG2.Cells[2,8])+
      StrToInt(SG2.Cells[2,9])+StrToInt(SG2.Cells[2,10])+
      StrToInt(SG2.Cells[2,11])+StrToInt(SG2.Cells[2,12])+
      StrToInt(SG2.Cells[2,13])+StrToInt(SG2.Cells[2,14])+
      StrToInt(SG2.Cells[2,15])+StrToInt(SG2.Cells[2,16])+
      StrToInt(SG2.Cells[2,17])+StrToInt(SG2.Cells[2,18])+
      StrToInt(SG2.Cells[2,19])+StrToInt(SG2.Cells[2,20])+
      StrToInt(SG2.Cells[2,21])+StrToInt(SG2.Cells[2,22])+
      StrToInt(SG2.Cells[2,23])+StrToInt(SG2.Cells[2,24])+
      StrToInt(SG2.Cells[2,25]));

   SG2.Cells[3,26]:=
      FloatToStr(StrToInt(SG2.Cells[3,1])+StrToInt(SG2.Cells[3,2])+
      StrToInt(SG2.Cells[3,3])+StrToInt(SG2.Cells[3,4])+
      StrToInt(SG2.Cells[3,5])+StrToInt(SG2.Cells[3,6])+
      StrToInt(SG2.Cells[3,7])+StrToInt(SG2.Cells[3,8])+
      StrToInt(SG2.Cells[3,9])+StrToInt(SG2.Cells[3,10])+
      StrToInt(SG2.Cells[3,11])+StrToInt(SG2.Cells[3,12])+
      StrToInt(SG2.Cells[3,13])+StrToInt(SG2.Cells[3,14])+
      StrToInt(SG2.Cells[3,15])+StrToInt(SG2.Cells[3,16])+
      StrToInt(SG2.Cells[3,17])+StrToInt(SG2.Cells[3,18])+
      StrToInt(SG2.Cells[3,19])+StrToInt(SG2.Cells[3,20])+
      StrToInt(SG2.Cells[3,21])+StrToInt(SG2.Cells[3,22])+
      StrToInt(SG2.Cells[3,23])+StrToInt(SG2.Cells[3,24])+
      StrToInt(SG2.Cells[3,25]));
 end;
Теперь разобью этот код по частям и напишу, что у меня не получается сделать).
Итак, здесь мне надо написать правильно условие через if...then или try...except, чтобы программа не выдавала ошибку, если не во все ячейки введены данные,т.е пусто, (будет хорошо, если покажете хотя бы на одном цикле, остальные попробую сделать по аналогии):
Код:
//количество оценок в SG3
   SG3.Cells[0,i]:=IntToStr(StrToInt(SG2.Cells[0,i])+
   StrToInt(SG2.Cells[1,i])+StrToInt(SG2.Cells[2,i])+
   StrToInt(SG2.Cells[3,i]));
 //средний бал в SG3
   SG3.Cells[1,i]:=
   FloatToStrF(2*StrToInt(SG2.Cells[0,i])/StrToInt(SG3.Cells[0,i])+
           3*StrToInt(SG2.Cells[1,i])/StrToInt(SG3.Cells[0,i])+
           4*StrToInt(SG2.Cells[2,i])/StrToInt(SG3.Cells[0,i])+
           5*StrToInt(SG2.Cells[3,i])/StrToInt(SG3.Cells[0,i]),ffFixed,1,1);
 //Качество успеваемости в SG3
   SG3.Cells[2,i]:=
   FloatToStrF(Trunc((StrToInt(SG2.Cells[2,i])+StrToInt(SG2.Cells[3,i]))*100)
              /StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
 //Успеваемость в SG3
   SG3.Cells[3,i]:=
   FloatToStrF(100-Trunc(StrToInt(SG2.Cells[0,i])*100)/StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
 //Обученность в SG3
   SG3.Cells[4,i]:=
   FloatToStrF(Trunc((2*StrToInt(SG2.Cells[0,i])+3*StrToInt(SG2.Cells[1,i])+
           4*StrToInt(SG2.Cells[2,i])+5*StrToInt(SG2.Cells[3,i]))*20)
           /StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
 //Четвертная оценка в SG3
   SG3.Cells[5,i]:=
   FloatToStrF(Trunc(2*StrToInt(SG2.Cells[0,i])+3*StrToInt(SG2.Cells[1,i])+
           4*StrToInt(SG2.Cells[2,i])+5*StrToInt(SG2.Cells[3,i]))
           /StrToInt(SG3.Cells[0,i]),ffFixed,0,0);
А здесь мне надо правильно записать цикл подсчета суммы ячеек в таблице по вертикали и умножения на число:
Код:
  SG2.Cells[0,26]:=
      FloatToStr(2*(StrToInt(SG2.Cells[0,1])+StrToInt(SG2.Cells[0,2])+
      StrToInt(SG2.Cells[0,3])+StrToInt(SG2.Cells[0,4])+
      StrToInt(SG2.Cells[0,5])+StrToInt(SG2.Cells[0,6])+
      StrToInt(SG2.Cells[0,7])+StrToInt(SG2.Cells[0,8])+
      StrToInt(SG2.Cells[0,9])+StrToInt(SG2.Cells[0,10])+
      StrToInt(SG2.Cells[0,11])+StrToInt(SG2.Cells[0,12])+
      StrToInt(SG2.Cells[0,13])+StrToInt(SG2.Cells[0,14])+
      StrToInt(SG2.Cells[0,15])+StrToInt(SG2.Cells[0,16])+
      StrToInt(SG2.Cells[0,17])+StrToInt(SG2.Cells[0,18])+
      StrToInt(SG2.Cells[0,19])+StrToInt(SG2.Cells[0,20])+
      StrToInt(SG2.Cells[0,21])+StrToInt(SG2.Cells[0,22])+
      StrToInt(SG2.Cells[0,23])+StrToInt(SG2.Cells[0,24])+
      StrToInt(SG2.Cells[0,25])));
Пробовал так:
Код:
  //SG2.Cells[0,26]:=FloatToStr(2*(StrToInt(SG2.Cells[0,i])));
Но не получается. Просто присваивает первую ячейку и все. Вот. Буду Вам всем очень благодарен если поможете)).
Ответить с цитированием