在按第二次加..的時候~如何顯示結果?? |
尚未結案
|
Linoa
一般會員 發表:2 回覆:2 積分:0 註冊:2005-04-05 發送簡訊給我 |
請問一下要如何寫在按第二次加、減、乘、除的時候,會顯示第一個數字和第二個數字相加、減、乘、除的結果啊??而以下的程式只能再按=的時候才會顯示結果~~
Procedure TForm1.FindResult(Sender: TObject); case Operation of
1: zno:=xno yno;
2: zno:=xno - yno;
3: zno:=xno * yno;
4: zno:=xno / yno;
else
exit;
end;
xno:=zno;
memo1.lines[0]:=FloatToStr(zno);
end; 發表人 - Linoa 於 2005/04/05 14:45:47
|
syntax
尊榮會員 發表:26 回覆:1139 積分:1258 註冊:2002-04-23 發送簡訊給我 |
|
Linoa
一般會員 發表:2 回覆:2 積分:0 註冊:2005-04-05 發送簡訊給我 |
unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls; type
TForm1 = class(TForm)
Memo1: TMemo; //顯示框
btnmr: TSpeedButton; //MR鍵
btnmc: TSpeedButton; //MC鍵
btnmpl: TSpeedButton; //M+鍵
btnmmi: TSpeedButton; //M-鍵
SpeedButton5: TSpeedButton; //數字鍵
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
btnplmi: TSpeedButton; //+/-符號鍵
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
btnpoint: TSpeedButton; //小數點
btndiv: TSpeedButton; //除
btntime: TSpeedButton; //除
btnmi: TSpeedButton; //減
btnpl: TSpeedButton; //加
btnbs: TSpeedButton; //BACKSPACE
btncre: TSpeedButton; //C
btnsqrt: TSpeedButton; //開根號
btn1d: TSpeedButton; //1除於X
btneql: TSpeedButton;
Label1: TLabel; //等號
procedure SpeedButton8Click(Sender: TObject);
procedure btnbsClick(Sender: TObject);
procedure btnsqrtClick(Sender: TObject);
procedure btn1dClick(Sender: TObject);
procedure btnplmiClick(Sender: TObject);
Procedure Do_Operation(Sender: TObject);
Procedure FindResult(Sender: TObject);
procedure btneqlClick(Sender: TObject);
procedure btnpointClick(Sender: TObject);
procedure btndivClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnplClick(Sender: TObject);
procedure btnmrClick(Sender: TObject);
procedure btnmcClick(Sender: TObject);
procedure btnmplClick(Sender: TObject);
procedure btnmmiClick(Sender: TObject);
procedure btncreClick(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1;
xno,yno,zno,mem1:real;
Operation:byte; //1=addition, 2=subtr., 3=Multip., 4=div
comma,ok,Pressed:boolean;
xsqrtno,xfrano:double;
implementation {$R *.DFM} Procedure tform1.Do_Operation(Sender: TObject);
begin
if operation<>0 then
begin
xno:=StrToFloat(memo1.lines[0]); end
else
begin
yno:=StrToFloat(memo1.lines[0]);
FindResult(Sender);
end;
Ok:=True;
Comma:=False;
end; Procedure TForm1.FindResult(Sender: TObject);
begin
case Operation of
1: zno:=xno + yno;
2: zno:=xno - yno;
3: zno:=xno * yno;
4: zno:=xno / yno;
else
exit;
end;
xno:=zno;
label1.Caption:=floattostr(operation)+floattostr(xno)+floattostr(yno)+floattostr(zno);
memo1.lines[0]:=FloatToStr(zno); end; procedure TForm1.SpeedButton8Click(Sender: TObject);
begin
if (memo1.lines[0]='0') then
memo1.Lines[0]:='';
if (ok and not Comma) then begin
memo1.lines[0]:='';
Ok:=False;
end;
if Length(memo1.Lines[0])>=15 then exit;
memo1.lines[0]:=memo1.lines[0]+tspeedbutton(sender).caption;
end; procedure TForm1.btnbsClick(Sender: TObject);
var xbs:string;strlen:integer;
begin
xbs:=memo1.lines[0];
strlen:=length(xbs);
if (strlen>0) then
xbs[strlen]:=#0;
memo1.lines[0]:=xbs;
end; procedure TForm1.btnsqrtClick(Sender: TObject);
var xsqrtno:double;
begin
xsqrtno:=strtofloat(memo1.lines[0]);
if (xsqrtno<0) then exit
else if (xsqrtno >= 0) then
xsqrtno:=sqrt(xsqrtno);
memo1.lines[0]:=floattostr(xsqrtno);
end; procedure TForm1.btn1dClick(Sender: TObject);
var xfrano:double;
begin
xfrano:=strtofloat(memo1.lines[0]);
if (xfrano=0) then exit
else if (xfrano<>0) then
xfrano:=1 / xfrano;
memo1.lines[0]:=floattostr(xfrano);
end; procedure TForm1.btnplmiClick(Sender: TObject);
var xplmi:double;
begin
xplmi:=strtofloat(memo1.lines[0]);
xplmi:=xplmi*-1;
memo1.lines[0]:=floattostr(xplmi);
end; procedure TForm1.btneqlClick(Sender: TObject);
begin
if (xno=0) or (Operation=0)then exit;
yno:=StrToFloat(memo1.lines[0]);
if Operation<>0 then FindResult(Sender);
xno:=StrToFloat(memo1.lines[0]);
yno:=0;
zno:=0;
operation=1;
end; procedure TForm1.btnpointClick(Sender: TObject);
begin
if (Pos('.',memo1.lines[0])>0) and (Operation=0) then exit;
if not ok then
memo1.lines[0]:=memo1.lines[0] '.'
else
memo1.lines[0]:='0.';
comma:=True; end; procedure TForm1.btndivClick(Sender: TObject);
begin
if yno=0 then exit
else if yno<>0 then
Do_Operation(Sender);
Operation:=4; end; procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines[0]:='0';
xno:=0;
yno:=0;
mem1:=0;
comma:=false;
Operation:=0;
zno:=0;
Pressed:=False;
end; procedure TForm1.btnplClick(Sender: TObject);
begin
if ok then exit;
operation:=tspeedbutton(sender).tag;
Do_operation(Sender); end; procedure TForm1.btnmrClick(Sender: TObject);
begin
memo1.Lines[0]:=FloatToStr(mem1);
If Operation=0 then xno:=StrToFloat(memo1.lines[0])
else yno:=StrToFloat(memo1.lines[0]);
end; procedure TForm1.btnmcClick(Sender: TObject);
begin
mem1:=0;
end; procedure TForm1.btnmplClick(Sender: TObject);
begin
Mem1:=Mem1 StrToFloat(memo1.lines[0]);
memo1.Visible:=True;
Do_operation(Sender); end; procedure TForm1.btnmmiClick(Sender: TObject);
begin
Mem1:=Mem1-StrToFloat(memo1.lines[0]);
memo1.Visible:=True;
end; procedure TForm1.btncreClick(Sender: TObject);
begin
// if operation=0 then
xno:=0;
// else
yno:=0;
zno:=0;
memo1.lines[0]:='0'; end; end.
|
lutienlung
一般會員 發表:3 回覆:5 積分:1 註冊:2005-04-01 發送簡訊給我 |
|
Linoa
一般會員 發表:2 回覆:2 積分:0 註冊:2005-04-05 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |