Advertisement
rikokurniawan

Keajaiban Angka Dan Huruf

Dec 16th, 2012
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.12 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ListBox1: TListBox;
  12.     Button1: TButton;
  13.     ListBox2: TListBox;
  14.     ListBox3: TListBox;
  15.     ListBox4: TListBox;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Edit1: TEdit;
  19.     Edit2: TEdit;
  20.     Label3: TLabel;
  21.     Bevel1: TBevel;
  22.     Label5: TLabel;
  23.     Label4: TLabel;
  24.     Edit3: TEdit;
  25.     procedure Button1Click(Sender: TObject);
  26.     procedure FormShow(Sender: TObject);
  27.   private
  28.     { Private declarations }
  29.     procedure bersih;
  30.   public
  31.     { Public declarations }
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. uses StrUtils;
  40.  
  41. {$R *.dfm}
  42.  
  43. procedure TForm1.bersih;
  44. begin
  45.   Edit1.Clear;
  46.   Edit2.Clear;
  47.   Edit3.Clear;
  48.   Label5.Caption:='';
  49. end;
  50.  
  51. procedure TForm1.Button1Click(Sender: TObject);
  52. var
  53.   i, i2 : Byte;
  54.   hasil : Int64;
  55.   hasil2 : Integer;
  56.   a,b, teks, proses, prosesangka : string;
  57. begin
  58. if Button1.Caption='Proses' then begin
  59.   for i := 1 to 9 do begin
  60.     a:=a+inttostr(i);
  61.     hasil:= strtoint(a)* 8 + i;
  62.     ListBox1.Items.Add(a + ' x 8 + '+ inttostr(i) + ' = '+ FloatToStr(hasil) );
  63.   end;  // for i := 1 to 9 do begin
  64.  
  65.   i := 0;
  66.   hasil := 0;
  67.   a:='';
  68.   b:='';
  69.  
  70.   for i := 1 to 9 do begin
  71.     a:=a+inttostr(i);
  72.     hasil:= strtoint(a)* 9 + (i+1);
  73.     ListBox2.Items.Add(a + ' x 9 + '+ IntToStr(i+1) + ' = '+ FloatToStr(hasil) );
  74.   end; // end  for i := 1 to 9 do begin
  75.  
  76.   i := 0;
  77.   hasil := 0;
  78.   a:='';
  79.   b:='';
  80.   for i := 9 Downto 2 do begin
  81.     a:=a+inttostr(i);
  82.     hasil:= strtoint(a)* 9 + (i-2);
  83.     ListBox3.Items.Add(a + ' x 9 + '+ IntToStr(i-2) + ' = '+ FloatToStr(hasil) );
  84.   end; // end for i := 9 Downto 2 do begin
  85.  
  86.   i := 0;
  87.   hasil := 0;
  88.   a:='';
  89.   b:='';
  90.   for i := 1 to 9 do begin
  91.     a:=a+IntToStr(1);
  92.     hasil:= StrToInt64(a)* StrToInt64(a) ;
  93.     ListBox4.Items.Add(a + ' x '+ a + ' = '+ IntToStr(hasil) );
  94.   end; // end for i := 1 to 9 do begin
  95.  
  96.   //Dibawah untuk menampilkan proses angka huruf serta hasil penjumlahannya
  97.   teks := Edit1.Text;
  98.   hasil2 := 0;
  99.   for i2 := 1 to Length(teks) do begin
  100.     if (teks[i2]>='A') and (teks[i2]<='Z') then Begin
  101.       hasil2 := hasil2 + Ord(teks[i2]) - 64;
  102.       Label5.Caption := IntToStr(hasil2) + ' %';
  103.  
  104.       //Logical Proses huruf
  105.       if i2 < length(teks) then proses:=proses + teks[i2]+ ' + '
  106.       else proses:=proses + teks[i2];
  107.  
  108.       //Logical Proses Angka
  109.       if i2 < length(teks) then prosesangka:=prosesangka + IntToStr(Ord(teks[i2])-64)+ ' + '
  110.       else prosesangka:=prosesangka + IntToStr(Ord(teks[i2])-64);
  111.     end; // if (teks[i2]>='A') and (teks[i2]<='Z') then Begin
  112.   end; //end for i2 := 1 to Length(teks) do begin
  113.   Edit2.text:=proses;
  114.   Edit3.Text:=prosesangka;
  115.  
  116.   Button1.Caption:='Ulangi';
  117.  
  118. end
  119. else if Button1.Caption='Ulangi' then begin
  120.   Button1.Caption:='Proses';
  121.   ListBox1.Clear;
  122.   ListBox2.Clear;
  123.   ListBox3.Clear;
  124.   ListBox4.Clear;
  125.   Bersih;
  126.   eDIT1.SetFocus;
  127. end;//end else
  128. end;
  129.  
  130. procedure TForm1.FormShow(Sender: TObject);
  131. begin
  132.   bersih;
  133.   Edit1.SetFocus;
  134. end;
  135.  
  136. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement