Страница 1 из 1
Помогите найти ошибку (выводится "is not a valid floati
![Непрочитанное сообщение Непрочитанное сообщение](./styles/prosilver/imageset/icon_post_target_unread.gif)
Добавлено:
23 окт 2008, 20:46:27
< Dem.IG >
- Код: Выделить всё
unit Laba2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label5: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label6: TLabel;
Label7: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i,n,k:integer;
a,b,c,x1,x2,x3,y1,y2,y3,z1,z2,z3,pp,P,S:real;
st1,st2,st3,str1,str2,str3:string;
implementation
{R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
st1:=Edit1.Text;
st2:=Edit2.Text;
st3:=Edit3.Text;
for i:=length(st1) downto 1 do if st1[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to n-1 do begin
str1:='';
str1:=str1+st1[i];
end;
x1:=StrToFloat(str1);
for i:=length(st2) downto 1 do if st2[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to n-1 do begin
str2:='';
str2:=str2+str2[i];
end;
x2:=StrToFloat(str2);
for i:=length(st3) downto 1 do if st3[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to n-1 do begin
str3:='';
str3:=str3+str3[i];
end;
x3:=StrToFloat(str3);
n:=length(st1); k:=1;
for i:=length(st1) downto 1 do if st1[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to length(st1) do if st1[i]=';' then begin
if k<i then k:=i;
end;
for i:=n+1 to k-1 do begin
str1:='';
str1:=str1+st1[i];
end;
y1:=StrToFloat(str1);
n:=length(st1); k:=1;
for i:=length(st2) downto 1 do if st2[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to length(st2) do if st2[i]=';' then begin
if k<i then k:=i;
end;
for i:=n+1 to k-1 do begin
str1:='';
str1:=str1+st2[i];
end;
y2:=StrToFloat(str2);
n:=length(st1); k:=1;
for i:=length(st3) downto 1 do if st3[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to length(st3) do if st3[i]=';' then begin
if k<i then k:=i;
end;
for i:=n+1 to k-1 do begin
str3:='';
str3:=str3+st3[i];
end;
y3:=StrToFloat(str3);
for i:=1 to length(st1) do if st1[i]=';' then begin
if n<i then n:=i;
end;
for i:=n+1 to length(st1) do begin
str1:='';
str1:=str1+st1[i];
end;
z1:=StrToFloat(str1);
for i:=1 to length(st2) do if st2[i]=';' then begin
if n<i then n:=i;
end;
for i:=n+1 to length(st2) do begin
str2:='';
str2:=str2+st2[i];
end;
z2:=StrToFloat(str2);
for i:=1 to length(st3) do if st3[i]=';' then begin
if n<i then n:=i;
end;
for i:=n+1 to length(st3) do begin
str3:='';
str3:=str3+st3[i];
end;
z3:=StrToFloat(str3);
a:=sqrt(sqr(x2-x1)+sqr(y2-y1)+sqr(z2-z1));
b:=sqrt(sqr(x3-x2)+sqr(y3-y2)+sqr(z3-z2));
c:=sqrt(sqr(x3-x1)+sqr(y3-y1)+sqr(z3-z1));
pp:=(a+b+c)/2;
S:=sqrt((pp*(pp-a)*(pp-b)*(pp-c)));
label6.Caption:=FloatToStr(S);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
st1:=Edit1.Text;
st2:=Edit2.Text;
st3:=Edit3.Text;
for i:=length(st1) downto 1 do if st1[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to n-1 do begin
str1:='';
str1:=str1+st1[i];
end;
x1:=StrToFloat(str1);
for i:=length(st2) downto 1 do if st2[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to n-1 do begin
str2:='';
str2:=str2+str2[i];
end;
x2:=StrToFloat(str2);
for i:=length(st3) downto 1 do if st3[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to n-1 do begin
str3:='';
str3:=str3+str3[i];
end;
x3:=StrToFloat(str3);
n:=length(st1); k:=1;
for i:=length(st1) downto 1 do if st1[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to length(st1) do if st1[i]=';' then begin
if k<i then k:=i;
end;
for i:=n+1 to k-1 do begin
str1:='';
str1:=str1+st1[i];
end;
y1:=StrToFloat(str1);
n:=length(st1); k:=1;
for i:=length(st2) downto 1 do if st2[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to length(st2) do if st2[i]=';' then begin
if k<i then k:=i;
end;
for i:=n+1 to k-1 do begin
str1:='';
str1:=str1+st2[i];
end;
y2:=StrToFloat(str2);
n:=length(st1); k:=1;
for i:=length(st3) downto 1 do if st3[i]=';' then begin
if n>i then n:=i;
end;
for i:=1 to length(st3) do if st3[i]=';' then begin
if k<i then k:=i;
end;
for i:=n+1 to k-1 do begin
str3:='';
str3:=str3+st3[i];
end;
y3:=StrToFloat(str3);
for i:=1 to length(st1) do if st1[i]=';' then begin
if n<i then n:=i;
end;
for i:=n+1 to length(st1) do begin
str1:='';
str1:=str1+st1[i];
end;
z1:=StrToFloat(str1);
for i:=1 to length(st2) do if st2[i]=';' then begin
if n<i then n:=i;
end;
for i:=n+1 to length(st2) do begin
str2:='';
str2:=str2+st2[i];
end;
z2:=StrToFloat(str2);
for i:=1 to length(st3) do if st3[i]=';' then begin
if n<i then n:=i;
end;
for i:=n+1 to length(st3) do begin
str3:='';
str3:=str3+st3[i];
end;
z3:=StrToFloat(str3);
a:=sqrt(sqr(x2-x1)+sqr(y2-y1)+sqr(z2-z1));
b:=sqrt(sqr(x3-x2)+sqr(y3-y2)+sqr(z3-z2));
c:=sqrt(sqr(x3-x1)+sqr(y3-y1)+sqr(z3-z1));
P:=a+b+c;
label7.Caption:=FloatToStr(P);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close
end;
end.
Помогите найти ошибку (выводится "is not a valid floati
![Непрочитанное сообщение Непрочитанное сообщение](./styles/prosilver/imageset/icon_post_target_unread.gif)
Добавлено:
25 окт 2008, 09:07:18
Void
< Dem.IG >, ошибку, глядя на этот текст, искать задолбаешься. А так просто совет, воспользоваться отладкой, незаменимая вещь.
Помогите найти ошибку (выводится "is not a valid floati
![Непрочитанное сообщение Непрочитанное сообщение](./styles/prosilver/imageset/icon_post_target_unread.gif)
Добавлено:
30 окт 2008, 00:43:09
Alex ilmarranen
Если мне не изменяет память это ошибка обычно при преобразовании строки въ число… въ твоёмъ случае во float…
Проверяй все строчки съ StrToFloat()…
Помогите найти ошибку (выводится "is not a valid floati
![Непрочитанное сообщение Непрочитанное сообщение](./styles/prosilver/imageset/icon_post_target_unread.gif)
Добавлено:
02 ноя 2008, 16:51:00
Гость
В обоих процедурах n неинициализировано. И вообще парсинг выглядит кривым.
Вынеси парсинг одной пары в отдельную процедуру, и выводи промежуточные результаты (две подстроки) на экран. Кажется, для одного из чисел ты захватываешь точку-с-запятой в строку, которую потом пытаешься преобразовать в число. Впрочем, я уже не помню, с чего в паскале индексы символов в строках начинаются - но не с нуля разве?