![]() |
|
#1
|
||||
|
||||
![]() Код:
procedure TForm1.SpeedButton1Click(Sender: TObject); var a:array[0..3] of integer; b:array[1..25] of integer; a1:array[0..3] of integer; b1:array[1..25] of integer; i,j,i1,j1:integer; begin for i:=1 to 25 do SG3.Cells[0,i]:=FloatToStr(StrToFloat(SG2.Cells[0,i])+ StrToFloat(SG2.Cells[1,i])+StrToFloat(SG2.Cells[2,i])+ StrToFloat(SG2.Cells[3,i])); for j1:=1 to 25 do SG3.Cells[1,j1]:=FloatToStr(2*StrToFloat(SG2.Cells[0,j1])/StrToFloat(SG3.Cells[0,i])+ 3*StrToFloat(SG2.Cells[1,j1])/StrToFloat(SG3.Cells[0,i])+4*StrToFloat(SG2.Cells[2,j1])/StrToFloat(SG3.Cells[0,i])+ 5*StrToFloat(SG2.Cells[3,j1])/StrToFloat(SG3.Cells[0,i])); end; Первый цикл работает отлично. Нужно чтобы во втором цикле умножение на 2,3,4,5 работало и каждое так сказать "слагаемое" еще делилось на результат суммы из первого цикла и ответ выводился в следующую ячейку. Проблема в том, что если я отключаю второй цикл, то первый работает, а если включаю его, то первый работает. Выводит только сообщение об ошибке, что нет всех данных в ячейках, с этим я потом разбеусь. Помогите мне объединить эти два цикла пожалста). Может я что то лишнее написал в процедуре, не могу пока понять что. Надо чтобы в ответе выводилась дробь (потому что есть деление). Благодарю за помощь). |
#2
|
|||
|
|||
![]() Ты во втором цикле искользуешь переменную i которая после цикла не имеет значения или оно больше 25 (сам не знаю =) ). Делай так:
Код:
var i, j: Integer; .... for i := 1 to 25 do begin SG3.Cells[0, i] := FloatToStr(StrToFloat(SG2.Cells[0, i])+ StrToFloat(SG2.Cells[1, i])+ StrToFloat(SG2.Cells[2, i])+ StrToFloat(SG2.Cells[3, i])); SG3.Cells[1, i] := FloatToStr(2*StrToFloat(SG2.Cells[0, i])/StrToFloat(SG3.Cells[0, i])+ 3*StrToFloat(SG2.Cells[1, i])/StrToFloat(SG3.Cells[0, i])+ 4*StrToFloat(SG2.Cells[2, i])/StrToFloat(SG3.Cells[0, i])+ 5*StrToFloat(SG2.Cells[3, i])/StrToFloat(SG3.Cells[0, i])); end; |
#3
|
||||
|
||||
![]() Почему этот код не работает так как мне надо:
Код:
SG2.Cells[0,26]:=FloatToStr(2*StrToInt(SG2.Cells[0,i ])); |
#4
|
|||
|
|||
![]() Если код работает не так, как тебе нада, то значит код действиетельно так работет))))
А насчет второй части, я чесное слово, не смог связать в цепочку эти слова... А тем более понять... Если никто не ответит, напиши нормально, не торопясь. А лучше с картинками того что нада =) |
#5
|
||||
|
||||
![]() Код:
SG2.Cells[0,26]:=FloatToStr(2*StrToInt(SG2.Cells[0,i ])); |
#6
|
||||
|
||||
![]() Вот весь код всей процедуры:
Код:
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]))); |
#7
|
|||
|
|||
![]() Во надо писать так
Код:
var i, j, Buf: Integer; begin { прогоняешь всю таблицу и ищешь пустые ячейки } for i := 1 to 25 do for j := 0 to 3 do if SG2.Cells[j,i] = '' then begin ShowMessage(Format('Ошибка в таблице! Ячейка [%d, %d]', [j+1, i])); Exit; end; { таблица заполнена выполянем код } 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); end; {а вот таким образом заменяется второй участок} for i := 0 to 3 do begin Buf := 0; for j := 1 to 25 do Buf := Buf + StrToInt(SG2.Cells[i, j]); SG2.Cells[i, 26] := IntToStr(Buf); end; А теперь по самой программе вопрос возник. Мне кажется ты делаешь ее неправильно, а точнее саму реализацию ![]() Сматри ты пишешь количество оценок в SG3, а насамом неле считаешь их сумму О_о Дальше я не стал вникать, НО то что если у тебя оценки 1, 1, 5, 2 и ты в четверти получаешь 4, ну это уже никак ((( |
#8
|
||||
|
||||
![]() Код:
for i := 0 to 3 do begin Buf := 0; for j := 1 to 25 do Buf := Buf + StrToInt(SG2.Cells[i, j]); SG2.Cells[i, 26] := IntToStr(Buf); end; Код:
for i := 0 to 5 do begin Buf := 0; for j := 1 to 25 do Buf := Buf + StrToInt(SG3.Cells[i, j]); SG3.Cells[i, 26] := IntToStr(Buf); end; |
#9
|
|||
|
|||
![]() Цитата:
Сам же сказал что 25 строк))) (точнее 26 если счить с серыми фиксированными), а тут ты пытешься записать SG3.Cells[i, 26], в таблице нет такой ячейки... И почему у тебя for i := 0 to 5 do ??? четыре столбца ведь |
#10
|
||||
|
||||
![]() А у кого нибудь есть исходники, которые бы помогли мне с моими вопросами? Если есть, то выложите пожалуйста)
|
#11
|
|||
|
|||
![]() А какие именно исходники нужны? Если очень уж нужна программа могу помочь, стукни 477771897
|