Bagi teman-teman yang ingin buat calculator niih aku punya rumusnya dengan satu edit. Itung-itung cari pahala
unit risky heri saputra;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
e1: TEdit;
b7: TButton;
b8: TButton;
b9: TButton;
bx: TButton;
b4: TButton;
b5: TButton;
b6: TButton;
bb: TButton;
b1: TButton;
b2: TButton;
b3: TButton;
bk: TButton;
b0: TButton;
bc: TButton;
bs: TButton;
bt: TButton;
l1: TLabel;
Button1: TButton;
procedure b0Click(Sender: TObject);
procedure b1Click(Sender: TObject);
procedure b2Click(Sender: TObject);
procedure b3Click(Sender: TObject);
procedure b4Click(Sender: TObject);
procedure b5Click(Sender: TObject);
procedure b6Click(Sender: TObject);
procedure b7Click(Sender: TObject);
procedure b8Click(Sender: TObject);
procedure b9Click(Sender: TObject);
procedure bcClick(Sender: TObject);
procedure btClick(Sender: TObject);
procedure bkClick(Sender: TObject);
procedure bbClick(Sender: TObject);
procedure bxClick(Sender: TObject);
procedure bsClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var a:Real;
implementation
{$R *.dfm}
procedure TForm1.b0Click(Sender: TObject);
begin
e1.Text:=e1.Text+b0.Caption;
end;
procedure TForm1.b1Click(Sender: TObject);
begin
e1.Text:=e1.Text+b1.Caption;
end;
procedure TForm1.b2Click(Sender: TObject);
begin
e1.Text:=e1.Text+b2.Caption;
end;
procedure TForm1.b3Click(Sender: TObject);
begin
e1.Text:=e1.Text+b3.Caption;
end;
procedure TForm1.b4Click(Sender: TObject);
begin
e1.Text:=e1.Text+b4.Caption;
end;
procedure TForm1.b5Click(Sender: TObject);
begin
e1.Text:=e1.Text+b5.Caption;
end;
procedure TForm1.b6Click(Sender: TObject);
begin
e1.Text:=e1.Text+b6.Caption;
end;
procedure TForm1.b7Click(Sender: TObject);
begin
e1.Text:=e1.Text+b7.Caption;
end;
procedure TForm1.b8Click(Sender: TObject);
begin
e1.Text:=e1.Text+b8.Caption;
end;
procedure TForm1.b9Click(Sender: TObject);
begin
e1.Text:=e1.Text+b9.Caption;
end;
procedure TForm1.bcClick(Sender: TObject);
begin
e1.Clear;
end;
procedure TForm1.btClick(Sender: TObject);
begin
l1.Caption:='+';
a:=StrToFloat(e1.Text);
e1.Text:=' ';
end;
procedure TForm1.bkClick(Sender: TObject);
begin
l1.Caption:='-';
a:=StrToFloat(e1.Text);
e1.Text:=' ';
end;
procedure TForm1.bbClick(Sender: TObject);
begin
l1.Caption:='/';
a:=StrToFloat(e1.Text);
e1.Text:=' ';
end;
procedure TForm1.bxClick(Sender: TObject);
begin
l1.Caption:='*';
a:=StrToFloat(e1.Text);
e1.Text:=' ';
end;
procedure TForm1.bsClick(Sender: TObject);
var
b,c:Real;
begin
b:=StrToFloat(e1.Text);
if l1.Caption='+' then c:=a+b else
if l1.Caption='-' then c:=a-b else
if l1.Caption='/' then c:=a/b else
if l1.Caption='*' then c:=a*b else
c:=a*b;
e1.Text:=FloatToStr(c);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Terminate;
end;
end.
Tidak ada komentar:
Posting Komentar