Advertisement
rikokurniawan

Loop For To dan DownTo dengan Listbox dan Combobox

Nov 29th, 2012
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.67 KB | None | 0 0
  1. unit Unit2;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm2 = class(TForm)
  11.     Label1: TLabel;
  12.     Label2: TLabel;
  13.     Edit1: TEdit;
  14.     Edit2: TEdit;
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Button3: TButton;
  18.     Button4: TButton;
  19.     Button5: TButton;
  20.     ListBox1: TListBox;
  21.     ComboBox1: TComboBox;
  22.     Button6: TButton;
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure Button4Click(Sender: TObject);
  25.     procedure Button1Click(Sender: TObject);
  26.     procedure Button6Click(Sender: TObject);
  27.     procedure Button3Click(Sender: TObject);
  28.     procedure Button5Click(Sender: TObject);
  29.     procedure Button2Click(Sender: TObject);
  30.   private
  31.     { Private declarations }
  32.   public
  33.     { Public declarations }
  34.     procedure bersih;
  35.   end;
  36.  
  37. var
  38.   Form2: TForm2;
  39.  
  40.  
  41. implementation
  42.  
  43. {$R *.dfm}
  44.  
  45. procedure TForm2.bersih;
  46. begin
  47.   Edit1.Clear;
  48.   Edit2.Clear;
  49.   ComboBox1.Clear;
  50.   ListBox1.Clear;
  51. end;
  52.  
  53. procedure TForm2.Button1Click(Sender: TObject);
  54. var i:Integer;
  55. begin
  56. if Edit1.Text = '' then begin
  57.   application.MessageBox('Datanya Masih Kosong'+#13+
  58.   'Silahkan Isikan dulu Datanya','Cek Pengisian...',MB_ICONWARNING);
  59.   Edit1.SetFocus;
  60.   EXIT;
  61. end;
  62.  
  63. if Edit2.Text = '' then begin
  64.   application.MessageBox('Batas Pengulangan Masih Kosong'+#13+
  65.   'Silahkan Isikan dulu Batas Pengulangannya','Cek Pengisian...',MB_ICONWARNING);
  66.   Edit2.SetFocus;
  67.   EXIT;
  68. end;
  69.  
  70. if (Edit1.Text <> '') And (Edit2.Text <> '') then begin
  71.   ComboBox1.Clear;
  72.   ListBox1.Clear;
  73.   for i := StrToInt(Edit1.Text) to StrToInt(Edit2.Text) do begin
  74.     ComboBox1.Items.Add(IntToStr(i));
  75.     ListBox1.Items.Add(IntToStr(i));
  76.   end;
  77. End;
  78. end;
  79.  
  80. procedure TForm2.Button3Click(Sender: TObject);
  81. var i,Sisa:Integer;
  82. begin
  83. if StrToInt(Edit1.Text) < StrToInt(Edit2.Text) then begin
  84.   ComboBox1.Clear;
  85.   ListBox1.Clear;
  86.  
  87.     for i := StrToInt(Edit1.Text) to StrToInt(Edit2.Text) do begin
  88.       Sisa:=i mod 2;
  89.       if sisa <> 0 then begin
  90.         ComboBox1.Items.Add(IntToStr(i));
  91.         ListBox1.Items.Add(IntToStr(i));
  92.       end;
  93.     end;
  94. end;
  95.  
  96. //List Dibawah Untuk Bilangan Ganjil Decrement
  97. if StrToInt(Edit1.Text) > StrToInt(Edit2.Text) then begin
  98.   ComboBox1.Clear;
  99.   ListBox1.Clear;
  100.  
  101.     for i := StrToInt(Edit1.Text) downto StrToInt(Edit2.Text) do begin
  102.       Sisa:=i mod 2;
  103.       if sisa <> 0 then begin
  104.         ComboBox1.Items.Add(IntToStr(i));
  105.         ListBox1.Items.Add(IntToStr(i));
  106.       end;
  107.     end;
  108. end;
  109. end;
  110.  
  111. procedure TForm2.Button4Click(Sender: TObject);
  112. var j,genap:Integer;
  113. begin
  114. //Genap Increment
  115. if StrToInt(Edit1.Text) < StrToInt(Edit2.Text) then begin
  116.   genap:=0;
  117.   ComboBox1.Clear;
  118.   ListBox1.Clear;
  119.   for j := StrToInt(Edit1.Text) to StrToInt(Edit2.Text) do begin
  120.     genap:=j mod 2;
  121.     if genap = 0 then begin
  122.       ComboBox1.Items.Add(IntToStr(j));
  123.       ListBox1.Items.Add(IntToStr(j));
  124.     end;
  125.   end;
  126. End;
  127.  
  128. //Genap Decrement
  129. if StrToInt(Edit1.Text) > StrToInt(Edit2.Text) then begin
  130.   genap:=0;
  131.   ComboBox1.Clear;
  132.   ListBox1.Clear;
  133.   for j := StrToInt(Edit1.Text) downto StrToInt(Edit2.Text) do begin
  134.     genap:=j mod 2;
  135.     if genap = 0 then begin
  136.       ComboBox1.Items.Add(IntToStr(j));
  137.       ListBox1.Items.Add(IntToStr(j));
  138.     end;
  139.   end;
  140. End;
  141.  
  142. end;
  143.  
  144. procedure TForm2.Button5Click(Sender: TObject);
  145. var i, sisa2, sisa3, sisa5, sisa7 : Integer;
  146. begin
  147.   //prima increment
  148.   if StrToInt(Edit1.Text)< StrToInt(Edit2.Text) then
  149.   begin
  150.     ComboBox1.Clear;
  151.     ListBox1.clear;
  152.     for i := StrToInt(Edit1.Text)to StrToInt(Edit2.Text) do
  153.       begin
  154.         if (i=2) or (i=3) or (i=5) or (i=7) then
  155.         begin
  156.           ComboBox1.Items.Add(IntToStr(i));
  157.           ListBox1.Items.Add(IntToStr(i))
  158.         end;
  159.         sisa2 := i mod 2;
  160.         sisa3 := i mod 3;
  161.         sisa5 := i mod 5;
  162.         sisa7 := i mod 7;
  163.         if (sisa2 <> 0) and (sisa3 <> 0) and (sisa5 <> 0) and (sisa7 <> 0) then
  164.         begin
  165.           ComboBox1.Items.Add(IntToStr(i));
  166.           ListBox1.Items.Add(IntToStr(i))
  167.         end;
  168.       end;
  169.   end;
  170.  
  171.   //prima decrement
  172.   if StrToInt(Edit1.Text)> StrToInt(Edit2.Text) then
  173.   begin
  174.     ComboBox1.Clear;
  175.     ListBox1.clear;
  176.     for i := StrToInt(Edit1.Text)downto StrToInt(Edit2.Text) do
  177.       begin
  178.         if (i=2) or (i=3) or (i=5) or (i=7) then
  179.         begin
  180.           ComboBox1.Items.Add(IntToStr(i));
  181.           ListBox1.Items.Add(IntToStr(i))
  182.         end;
  183.         sisa2 := i mod 2;
  184.         sisa3 := i mod 3;
  185.         sisa5 := i mod 5;
  186.         sisa7 := i mod 7;
  187.         if (sisa2 <> 0) and (sisa3 <> 0) and (sisa5 <> 0) and (sisa7 <> 0) then
  188.         begin
  189.           ComboBox1.Items.Add(IntToStr(i));
  190.           ListBox1.Items.Add(IntToStr(i))
  191.         end;
  192.       end;
  193.   end;
  194. end;
  195.  
  196. procedure TForm2.Button6Click(Sender: TObject);
  197. begin
  198.   bersih;
  199. end;
  200.  
  201. procedure TForm2.FormCreate(Sender: TObject);
  202. Var i : Int64;
  203. begin
  204.   bersih;
  205. end;
  206.  
  207. procedure TForm2.Button2Click(Sender: TObject);
  208. var i:Integer;
  209. begin
  210. if Edit1.Text = '' then begin
  211.   application.MessageBox('Datanya Masih Kosong'+#13+
  212.   'Silahkan Isikan dulu Datanya','Cek Pengisian...',MB_ICONWARNING);
  213.   Edit1.SetFocus;
  214.   EXIT;
  215. end;
  216.  
  217. if Edit2.Text = '' then begin
  218.   application.MessageBox('Batas Pengulangan Masih Kosong'+#13+
  219.   'Silahkan Isikan dulu Batas Pengulangannya','Cek Pengisian...',MB_ICONWARNING);
  220.   Edit2.SetFocus;
  221.   EXIT;
  222. end;
  223.  
  224. if (Edit1.Text <> '') And (Edit2.Text <> '') then begin
  225.   ComboBox1.Clear;
  226.   ListBox1.Clear;
  227.   for i := StrToInt(Edit1.Text) to StrToInt(Edit2.Text) do begin
  228.     ComboBox1.Items.Add(IntToStr(i));
  229.     ListBox1.Items.Add(IntToStr(i)+''+IntToStr(i+1));
  230.   end;
  231. End;
  232. end;
  233.  
  234. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement