為什麼最後 end; 的地方,總是無法順利執行… |
答題得分者是:Stallion
|
kajinex
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2005-10-10 發送簡訊給我 |
我試了好久,但是總是無法順利執行,
不知道是不是分號的問題,可否幫我解決,謝謝。
------------------
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Math; type
TForm1 = class(TForm)
Label1: TLabel;
ediInput: TEdit;
Button1: TButton;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
x,y:Extended;
begin
x:=strtofloat(ediInput.Text);
if x>3 then
begin
y:=x+3;
end
else
if (x>=1) and (x<=3) then
begin
y:=Power(x,2);
end
else
if (x>0) and (x<1) then
begin
y:=Sqrt(x);
end
else
y:=0;
end;
label2.Caption:=floattoStr(y);//讓y值轉成字串,再經由 label2顯現出來
end;
end.
|
Stallion
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
你是要這樣嗎?
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Math; type TForm1 = class(TForm) ediInput: TEdit; Button1: TButton; Label1: TLabel; Label2: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var x,y:Extended; begin x:=strtofloat(ediInput.Text); if x>3 then y:=x 3 else if (x>=1) and (x<=3) then y:=Power(x,2) else if (x>0) and (x<1) then y:=Sqrt(x) else y:=0; label2.Caption:=floattoStr(y);//讓y值轉成字串,再經由 label2顯現出來 end;----------------------- Practice makes perfect. |
kajinex
一般會員 ![]() ![]() 發表:1 回覆:1 積分:0 註冊:2005-10-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |