![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
при пустой ячейке выскакивает "is not a valid floating point valu [D7, XP]
ser_tr © (2007-11-07 09:15:00)ЗДРАВТСВУЙТЕ, ПАМАГИТЕ ПЛИЗ ламеру, НЕ могу сдать зачет по Delphi, а я в нем индюк. Есть таблица, в которой вводим факт 1,2,3,4 год. Таблица расчитывает удельный вес по каждому году плюс отклонения.
Если же не ввести в одну из ячеек число (т.е. ячейка будет пустая), то выскакивает ошибка "is not a valid floating point value". Я перерыл много форумов, но так и ничего не нашел..... (или скорей всего не понял, т.к. повторюсь, я индюк). Вот кусочек программы. Заранее Спасибо.
procedure TForm1.BitBtn2Click(Sender: TObject);
var
Value: Double; ch: Currency;
q : Integer;
begin
for i:=1 to StringGrid1.RowCount-2 do
for q:=1 to 8 do If q mod 2 = 1 then form1.StringGrid1.Cells[q,kol+1]:=currToStr(strtocurr(form1.StringGrid1.Cells[q,kol+1])+strtocurr(form1.StringGrid1.Cells[q,i]));
for i:=1 to StringGrid1.RowCount-2 do begin
//1 год удельный вес
StringGrid1.Cells[2,i]:=FloatToStr(100/strtofloat(StringGrid1.Cells[1,kol+1])*strtofloat(StringGrid1.Cells[1,i]));
StringGrid1.Cells[2,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[2,kol+1])+strtofloat(StringGrid1.Cells[2,i]));
//2 год удельный вес
StringGrid1.Cells[4,i]:=FloatToStr(100/strtofloat(StringGrid1.Cells[3,kol+1])*strtofloat(StringGrid1.Cells[3,i]));
StringGrid1.Cells[4,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[4,kol+1])+strtofloat(StringGrid1.Cells[4,i]));
//3 год удельный вес
StringGrid1.Cells[6,i]:=FloatToStr(100/strtofloat(StringGrid1.Cells[5,kol+1])*strtofloat(StringGrid1.Cells[5,i]));
StringGrid1.Cells[6,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[6,kol+1])+strtofloat(StringGrid1.Cells[6,i]));
//3-год удельный вес фактический
StringGrid1.Cells[8,i]:=FloatToStr(100/strtofloat(StringGrid1.Cells[7,kol+1])*strtofloat(StringGrid1.Cells[7,i]));
StringGrid1.Cells[8,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[8,kol+1])+strtofloat(StringGrid1.Cells[8,i]));
//% выполнения плана
StringGrid1.Cells[9,i]:=FloatToStr(strtofloat(StringGrid1.Cells[5,i])/strtofloat(StringGrid1.Cells[7,i])*100);
StringGrid1.Cells[9,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[5,kol+1])/strtofloat(StringGrid1.Cells[7,kol+1])*100);
//1-года
StringGrid1.Cells[10,i]:=FloatToStr(strtofloat(StringGrid1.Cells[5,i])/strtofloat(StringGrid1.Cells[1,i])*100);
StringGrid1.Cells[10,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[5,kol+1])/strtofloat(StringGrid1.Cells[1,kol+1])*100);
//2-года
StringGrid1.Cells[11,i]:=FloatToStr(strtofloat(StringGrid1.Cells[5,i])/strtofloat(StringGrid1.Cells[3,i])*100);
StringGrid1.Cells[11,kol+1]:=FloatToStr(strtofloat(StringGrid1.Cells[5,kol+1])/strtofloat(StringGrid1.Cells[3,kol+1])*100);
end;
for i:=1 to 11 do begin
for j:=1 to kol+1 do begin
if (i mod 2 = 0) or (i=11) or (j=kol+1) or(i=9) then // округление только ячеек, где производится расчет
form1.StringGrid1.Cells[i,j]:= okruglenie(StrTocurr(form1.StringGrid1.Cells[i,j]), 2);
end;
end;
end;
Anatoly Podgoretsky (2007-11-07 14:13:00) [41]> Галинка (07.11.2007 10:30:09) [9]
Фокусировать можно. А проверка обязательно, нет смысла производить какие то вычисления при неверных данных.
Anatoly Podgoretsky (2007-11-07 14:11:00) [42]> Ega23 (07.11.2007 10:25:07) [7]
Компактная запись.
Галинка (2007-11-07 10:30:00) [43]Ну самое очевидное, прорверять заполнены ли все ячейки таблицы. Еще до конвертации. Что-то типа:
boolean IsCompleat(_grid : TStringGrid)
var
i,j : integer;
begin
Result := true;
for i=0 to _grid.RowCount-1 do
for j=0 to _grid.ColCount-1 do
if _grid.Cell[i,j] = "" then
begin
ShowMessage('There is empty cells in grid !!!');
//не уверена, есть ли у ячейки метод SetFocus
Result := false;
break;
end;
end;
Kolan (2007-11-07 10:27:00) [44]у вал название непонятное, и параметров больше, и енто вообще из паскаля истчо
Ega23 (2007-11-07 10:25:00) [45]
> TryFloatToStr ?
А разница?
Kolan (2007-11-07 10:20:00) [46]> На словах то оно вроде понятно, но как реализовать в проге
var
Val: Double;
if not TryStrToFloat(StringGrid1.Cells[5,i], Val) then
ShowMessage('Не флоат это, не флоат!')
else
ShowMessage('А вот это пойдёт.')
clickmaker (2007-11-07 10:18:00) [47]
> как реализовать в проге.....
вот не понимаю: зачем писать в форум, если все равно ответы не читаешь?
тихо самому с собою нравится вести беседу?
ser_tr (2007-11-07 10:13:00) [48]
> Галинка © (07.11.07 09:57) [2]
> Правильно. Если пробел или пустое месть попытаться перевести
> в Float (StrToFloat) то и будет подобная ошибка конвертации
На словах то оно вроде понятно, но как реализовать в проге.....
Kolan (2007-11-07 10:00:00) [49]
Ega23 © (07.11.07 09:39)
> Val
TryFloatToStr?
Галинка (2007-11-07 09:57:00) [50]Правильно. Если пробел или пустое месть попытаться перевести в Float (StrToFloat) то и будет подобная ошибка конвертации.
Ega23 (2007-11-07 09:39:00) [51]
var
ss : string
Code : Integer;
Value : Double;
begin
...............
ss := StringGrid1.Cells[5,i]
Val(ss, Value, Code);
if Code<>0 then
ShowMessage('StringGrid1.Cells[5,i] - Неправильное число');
end;
Приблизительно, в таком вот аксепте