Arsip: Pemisah ribuan saat input edit


by rifaat in more 11 years ago 2315
Pemisah ribuan saat input edit


//PEMISAH RIBUAN SAAT TEXT EDIT DIKETIK (Contoh sampai 1,000,000)
   //---------------------------------------------------------------
   
   //Event OnKeyPress di Edit1.text isikan :
   if not (key in ['0'..'9',#8]) then
   key:=#0;
   // Saat angka diketik
   // Contoh 1,000
   if (Edit1.SelStart=3) and (not (key in [#8])) then
   begin
   edit1.Text:=copy(edit1.Text,1,1)+','+
   copy(edit1.Text,2,1)+
   copy(edit1.Text,3,1)+
   copy(edit1.Text,4,1);
   Edit1.SelStart:=5;
   end;
   // Contoh 10,000 
   if (Edit1.SelStart=5) and (not (key in [#8])) then
   begin
   edit1.Text:=copy(edit1.Text,1,1)+
   copy(edit1.Text,3,1)+','+
   copy(edit1.Text,4,1)+
   copy(edit1.Text,5,1)+
   copy(edit1.Text,6,1);
   Edit1.SelStart:=7;
   end;
   // Contoh 100,000
  if (Edit1.SelStart=6) and (not (key in [#8])) then
  begin
  edit1.Text:=copy(edit1.Text,1,1)+
  copy(edit1.Text,2,1)+
  copy(edit1.Text,4,1)+','+
  copy(edit1.Text,5,1)+
  copy(edit1.Text,6,1)+
  copy(edit1.Text,7,1);
  Edit1.SelStart:=8;
  end;
  // Contoh 1,000,000
  if (Edit1.SelStart=7) and (not (key in [#8])) then
  begin
  edit1.Text:=copy(edit1.Text,1,1)+','+
  copy(edit1.Text,2,1)+
  copy(edit1.Text,3,1)+
  copy(edit1.Text,5,1)+','+
  copy(edit1.Text,6,1)+
  copy(edit1.Text,7,1)+
  copy(edit1.Text,9,1);
  Edit1.SelStart:=8;
  end;
   // Saat Backspace di tekan
   // Contoh 1,000
   if (key=#8) and (edit1.selstart=5) then
   begin
   Edit1.Text:=copy(edit1.Text,1,1)+
             copy(edit1.Text,3,1)+
             copy(edit1.Text,4,1)+
             copy(edit1.Text,5,1);
   Edit1.SelStart:=5;
   end;
   // Contoh 10,000
   if (key=#8) and (edit1.selstart=6) then
   begin
   Edit1.Text:=copy(edit1.Text,1,1)+','+
             copy(edit1.Text,2,1)+
             copy(edit1.Text,4,1)+
             copy(edit1.Text,5,1)+
             copy(edit1.Text,6,1);
   Edit1.SelStart:=6;
   end;
   // Contoh 100,000
   if (key=#8) and (edit1.selstart=7) then
   begin
   Edit1.Text:=copy(edit1.Text,1,1)+
             copy(edit1.Text,2,1)+','+
             copy(edit1.Text,3,1)+
             copy(edit1.Text,5,1)+
             copy(edit1.Text,6,1)+
             copy(edit1.Text,7,1);
   Edit1.SelStart:=7;
   end;
   // Contoh 1,000,000
   if (key=#8) and (edit1.selstart=9) then
   begin
   Edit1.Text:=copy(edit1.Text,1,1)+
             copy(edit1.Text,3,1)+
             copy(edit1.Text,4,1)+','+
             copy(edit1.Text,5,1)+
             copy(edit1.Text,7,1)+
             copy(edit1.Text,8,1)+
             copy(edit1.Text,9,1);
   Edit1.SelStart:=9;
   end;
   


// Selesai

Nama : Rifaat
Kerjaan : Pekerja di BRI Kanwil Palembang
Hobi 1 : Buat program delphi
Hobi 2 : Nonton film fiksi ilmiah
Email 1 : ahmad_riffaat@bri.co.id
Email 2 : ahmad.rifaat@yahoo.co.id
HP : 0816-321-723-65

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com