Экспертная система Delphi.int.ru

Сообщество программистов
Общение, помощь, обмен опытом

Логин:
Пароль:
Регистрация | Забыли пароль?

Delphi.int.ru Expert

Другие разделы портала

Переход к вопросу:

#   

Статистика за сегодня:  


Лучшие эксперты

Подробнее »



Вопрос # 5 290

/ вопрос открыт /

Приветствую, уважаемые эксперты!
Подскажите пожалуйста в чем может быть проблема в коде. После третьей строки вылетает ошибка " is not a valid floating point value

Приложение:
  1. StringGrid1.Cells[4,5]:=query.Fields[0].AsString;
  2. s:= StrToCurr(StringGrid1.Cells[1,5]);
  3. a:= StrToCurr(StringGrid1.Cells[2,5]);
  4. if StrToInt(StringGrid1.Cells[1,5])= 0 then
  5. begin
  6. b:= 0;
  7. end
  8. else
  9. begin
  10. b:= s/a-1;
  11. end;
  12. if StrToInt(StringGrid1.Cells[2,5])= 0 then
  13. begin
  14. b:= 0;
  15. end
  16. else
  17. begin
  18. b:= s/a-1;
  19. end;
  20. StringGrid1.Cells[3,5]:= CurrToStr(b)+'%';
  21.  
  22. s:= StrToCurr(StringGrid1.Cells[1,5]);
  23. a:= StrToCurr(StringGrid1.Cells[4,5]);
  24. if StrToInt(StringGrid1.Cells[1,5])= 0 then
  25. begin
  26. b:= 0;
  27. end
  28. else
  29. begin
  30. b:= s/a-1;
  31. end;
  32. if StrToInt(StringGrid1.Cells[4,5])= 0 then
  33. begin
  34. b:= 0;
  35. end
  36. else
  37. begin
  38. b:= s/a-1;
  39. end;
  40. StringGrid1.Cells[5,5]:= CurrToStr(b)+'%';


mobidik Вопрос ожидает решения (принимаются ответы, доступен мини-форум)

Вопрос задал: mobidik (статус: Посетитель)
Вопрос отправлен: 16 мая 2011, 10:21
Состояние вопроса: открыт, ответов: 1.

Ответ #1. Отвечает эксперт: Вадим К

Здравствуйте, mobidik!
Дело в том, что функции вида StrTo* требуют, что бы в строке была записано именно число. И не пробелом больше.
Функции StrToCurr и StrToFloat хотят в качестве разделителя целой и дробной части видеть системный разделитель (у одних это точка, у других запятая, всё зависит от системных настроек). Также эти функции будут "ругатся", если им дать не строковое представление числа, а просто пробелы или символы.

В Вашем варианте нужно смотреть, что именно Вы туда ввели, но подозреваю, просто точку вместо запятой. (здесь http://www.delphibasics.co.uk/RTL.asp?Name=StrToCurr есть примеры ещё).

Что же делать? для начала нужно понять, что же не так вводится, а потом либо просто правильно вводить, либо добавить защитных механизмов. К примеру try - except ( по ссылке выше есть пример оного. В этом случае можно будет выводить свои ошибки, к примеру "нужно вводить через запятую!").

Ответ отправил: Вадим К (статус: Академик)
Время отправки: 16 мая 2011, 10:46


Мини-форум вопроса

Всего сообщений: 3; последнее сообщение — 16 мая 2011, 11:36; участников в обсуждении: 2.
mobidik

mobidik (статус: Посетитель), 16 мая 2011, 11:00 [#1]:

Вадим К: Спасибо за ответ.
Видимо как я понял при формировании таблицы в некоторых столбцах образуется пустота. А как можно сделать так чтобы в пустые столбцы автоматически ставился ноль?
Вадим К

Вадим К (статус: Академик), 16 мая 2011, 11:21 [#2]:

а кто мешает? Покажите код формирования таблицы, может и придумаем красивый код. А можно при вводе данных проверять, не пусто ли там через if (StringGrid1.Cells[1,5] <> '')
Галочка "подтверждения прочтения" - вселенское зло.
mobidik

mobidik (статус: Посетитель), 16 мая 2011, 11:36 [#3]:

dbs.Close;
query.close;
query.SQL.Text:= 'SELECT sum(doc_summ) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date between :d1
and :d2 and card_number='''+Edit1.Text+''' )';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=DateTimePicker1.Date;
query.Parameters.ParamByName('d2').Value:=DateTimePicker2.Date;
query.Open;
 
 
StringGrid1.Cells[1,1]:=CurrToStr(query.Fields[0].AsCurrency);
StringGrid1.Cells[1,0]:=Format('&#207;&#229;&#240;&#232;&#238;&#228; &#224;&#234;&#246;&#232;&#232; %s -
%s',[DateToStr(DateTimePicker1.Date),DateToStr(DateTimePicker2.Date)]);
 
query.Close;
query.SQL.Text:= 'SELECT sum(doc_summ) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date between :d1
and :d2 and card_number='''+Edit1.Text+''') ';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(IncMonth(DateTimePicker1.Date,-1),-1);
query.Parameters.ParamByName('d2').Value:=IncYear(IncMonth(DateTimePicker2.Date,-1),-1);
query.Open;
//StringGrid1.Cells[1,1]:=query.Fields[0].AsString;
StringGrid1.Cells[2,1]:=CurrToStr(query.Fields[0].AsCurrency);
StringGrid1.Cells[2,0]:=Format('&#207;&#240;&#229;&#228;&#251;&#228;&#243;&#249;&#232;&#233;
&#239;&#229;&#240;&#232;&#238;&#228; %s -
%s',[DateToStr(IncYear(IncMonth(DateTimePicker1.Date,-1),-1)),DateToStr(IncYear(IncMonth(DateTimePicker2.Date,-1),-1))]);
 
query.Close;
query.SQL.Text:= 'SELECT sum(doc_summ) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date between :d1
and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(DateTimePicker1.Date,-1);
query.Parameters.ParamByName('d2').Value:=IncYear(DateTimePicker2.Date,-1);
query.Open;
StringGrid1.Cells[4,1]:=CurrToStr(query.Fields[0].AsCurrency);
StringGrid1.Cells[4,0]:=Format('&#192;&#237;&#224;&#235;&#238;&#227;&#232;&#247;&#237;&#251;&#233;
&#239;&#229;&#240;&#232;&#238;&#228; &#239;&#240;&#238;&#248;&#235;&#238;&#227;&#238; &#227;&#238;&#228;&#224; %s -
%s',[DateToStr(IncYear(DateTimePicker1.Date,-1)),DateToStr(IncYear(DateTimePicker2.Date,-1))]);
 
s:= StrToCurr(StringGrid1.Cells[1,1]);
a:= StrToCurr(StringGrid1.Cells[2,1]);
 
if StrToInt(StringGrid1.Cells[1,1])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
if StrToInt(StringGrid1.Cells[2,1])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
StringGrid1.Cells[3,1]:= CurrToStr(b)+'%';
 
s:= StrToCurr(StringGrid1.Cells[1,1]);
a:= StrToCurr(StringGrid1.Cells[4,1]);
if StrToInt(StringGrid1.Cells[1,1])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
 
if StrToInt(StringGrid1.Cells[4,1])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
StringGrid1.Cells[5,1]:= CurrToStr(b)+'%';
 
//&#205;&#224;&#247;&#224;&#235;&#238; &#237;&#238;&#226;&#238;&#233; &#241;&#242;&#240;&#238;&#234;&#232;
&#215;&#232;&#241;&#235;&#238; &#239;&#238;&#234;&#243;&#239;&#238;&#234;
 
query.Close;
query.SQL.Text:= 'SELECT distinct count(doc_number) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date
between :d1 and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=DateTimePicker1.Date;
query.Parameters.ParamByName('d2').Value:=DateTimePicker2.Date;
query.Open;
StringGrid1.Cells[1,2]:=query.Fields[0].AsString;
 
query.Close;
query.SQL.Text:= 'SELECT distinct count(doc_number) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date
between :d1 and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(IncMonth(DateTimePicker1.Date,-1),-1);
query.Parameters.ParamByName('d2').Value:=IncYear(IncMonth(DateTimePicker2.Date,-1),-1);
query.Open;
StringGrid1.Cells[2,2]:=query.Fields[0].AsString;
 
query.Close;
query.SQL.Text:= 'SELECT distinct count(doc_number) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date
between :d1 and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(DateTimePicker1.Date,-1);
query.Parameters.ParamByName('d2').Value:=IncYear(DateTimePicker2.Date,-1);
query.Open;
StringGrid1.Cells[4,2]:=query.Fields[0].AsString;
 
s:= StrToCurr(StringGrid1.Cells[1,2]);
a:= StrToCurr(StringGrid1.Cells[2,2]);
if StrToInt(StringGrid1.Cells[1,2])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
if StrToInt(StringGrid1.Cells[2,2])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
StringGrid1.Cells[3,2]:= CurrToStr(b)+'%';
s:= StrToCurr(StringGrid1.Cells[1,2]);
a:= StrToCurr(StringGrid1.Cells[4,2]);
if StrToInt(StringGrid1.Cells[1,2])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
if StrToInt(StringGrid1.Cells[4,2])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
StringGrid1.Cells[5,2]:= CurrToStr(b)+'%';
 
 
 
//&#205;&#224;&#247;&#224;&#235;&#238; &#237;&#238;&#226;&#238;&#233; &#241;&#242;&#240;&#238;&#234;&#232;
&#194;&#251;&#228;&#224;&#237;&#238; &#234;&#224;&#240;&#242;
 
query.Close;
query.SQL.Text:= 'SELECT distinct count(active) FROM card WHERE (date_activated between :d1 and :d2 and
card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=DateTimePicker1.Date;
query.Parameters.ParamByName('d2').Value:=DateTimePicker2.Date;
query.Open;
StringGrid1.Cells[1,3]:=query.Fields[0].AsString;
 
query.Close;
query.SQL.Text:= 'SELECT distinct count(active) FROM card WHERE (date_activated between :d1 and :d2 and
card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(IncMonth(DateTimePicker1.Date,-1),-1);
query.Parameters.ParamByName('d2').Value:=IncYear(IncMonth(DateTimePicker2.Date,-1),-1);
query.Open;
StringGrid1.Cells[2,3]:=query.Fields[0].AsString;
 
query.Close;
query.SQL.Text:= 'SELECT distinct count(active) FROM card WHERE (date_activated between :d1 and :d2 and
card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(DateTimePicker1.Date,-1);
query.Parameters.ParamByName('d2').Value:=IncYear(DateTimePicker2.Date,-1);
query.Open;
StringGrid1.Cells[4,3]:=query.Fields[0].AsString;
 
s:= StrToCurr(StringGrid1.Cells[1,3]);
a:= StrToCurr(StringGrid1.Cells[2,3]);
if StrToInt(StringGrid1.Cells[1,3])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
if StrToInt(StringGrid1.Cells[2,3])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
StringGrid1.Cells[3,3]:= CurrToStr(b)+'%';
 
s:= StrToCurr(StringGrid1.Cells[1,3]);
a:= StrToCurr(StringGrid1.Cells[4,3]);
if StrToInt(StringGrid1.Cells[1,3])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
if StrToInt(StringGrid1.Cells[4,3])= 0 then
begin
b:= 0;
end
else
begin
b:= s/a-1;
end;
StringGrid1.Cells[5,3]:= CurrToStr(b)+'%';
 
 
 
//&#205;&#224;&#247;&#224;&#235;&#238; &#237;&#238;&#226;&#238;&#233; &#241;&#242;&#240;&#238;&#234;&#232;
&#209;&#240;&#229;&#228;&#237;&#232;&#233; &#247;&#229;&#234;, &#240;&#243;&#225;
 
query.Close;
query.SQL.Text:= 'SELECT sum(doc_summ/2) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date between
:d1 and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=DateTimePicker1.Date;
query.Parameters.ParamByName('d2').Value:=DateTimePicker2.Date;
query.Open;
StringGrid1.Cells[1,4]:=query.Fields[0].AsString;
 
query.Close;
query.SQL.Text:= 'SELECT sum(doc_summ/2) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date between
:d1 and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(IncMonth(DateTimePicker1.Date,-1),-1);
query.Parameters.ParamByName('d2').Value:=IncYear(IncMonth(DateTimePicker2.Date,-1),-1);
query.Open;
StringGrid1.Cells[2,4]:=query.Fields[0].AsString;
 
query.Close;
query.SQL.Text:= 'SELECT sum(doc_summ/2) FROM doc inner join card on doc.card_id=card.card_id WHERE (doc_date between
:d1 and :d2 and card_number='''+Edit1.Text+''')';
query.Parameters.ParseSQL(query.SQL.Text, true);
query.Parameters.ParamByName('d1').Value:=IncYear(DateTimePicker1.Date,-1);
query.Parameters.ParamByName('d2').Value:=IncYear(DateTimePicker2.Date,-1);
query.Open;
StringGrid1.Cells[4,4]:=query.Fields[0].AsString;
 
//s:= StrToCurr(StringGrid1.Cells[1,4]);
//a:= StrToCurr(StringGrid1.Cells[2,4]);
//if StrToInt(StringGrid1.Cells[1,4])= 0 then
//begin
//b:= 0;
//end
//else
//begin
//b:= s/a-1;
//end;
//if StrToInt(StringGrid1.Cells[2,4])= 0 then
//begin
//b:= 0;
//end
///else
//begin
//b:= s/a-1;
//end;
//StringGrid1.Cells[3,4]:= CurrToStr(b)+'%';
 
//s:= StrToCurr(StringGrid1.Cells[1,4]);
//a:= StrToCurr(StringGrid1.Cells[4,4]);
//if StrToInt(StringGrid1.Cells[1,4])= 0 then
//begin
//b:= 0;
//end
//else
//begin
//b:= s/a-1;
//end;
//if StrToInt(StringGrid1.Cells[4,4])= 0 then
//begin
//b:= 0;
//end
//else
//begin
//b:= s/a-1;
//end;
//StringGrid1.Cells[5,4]:= CurrToStr(b)+'%';

Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.

Версия движка: 2.6+ (26.01.2011)
Текущее время: 22 февраля 2025, 16:48
Выполнено за 0.04 сек.