//--------------------------------------------------------------------------- #include #include #include #define maxL 100 #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma resource "*.dfm" char *digit[10]= { "ศูนย์","หนึ่ง","สอง","สาม","สี่", "ห้า","หก","เจ็ด","แปด","เก้า" }; char *spdigit[3]= { "","เอ็ด","ยี่" }; char *radix[7]= { "","สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน" }; char thairead[maxL]; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::ClearBtnClick(TObject *Sender) { Edit1->Clear( ); Edit2->Clear( ); Panel->Caption= " "; } //--------------------------------------------------------------------------- void __fastcall TForm1::CheckThaiRead(int Count,int i,int k,char *rd) { char *st; //---------------- Read Digits ---------------// //------------- Case Zero number -------------// if ((Count > 1)&(k == 0)) st=""; //-------------- Case One number -------------// else if (((Count > 1)&(i == Count)&(k == 1)) | ((Count > 7)&((Count-(6+i))== 0)&(k == 1))) st= spdigit[1]; else if (((Count > 1)&(i == Count-1)&(k == 1)) | ((Count > 7)&((Count-(6+i))== 1)&(k == 1))) st= ""; //------------- Case Two number --------------// else if (((Count > 1)&(i == Count-1)&(k == 2)) | ((Count > 7)&((Count-(6+i))== 1)&(k == 2))) st= spdigit[2]; else st= digit[k]; strcat(rd,st); //--------------------------------------------// //---------------- Read Radixs ---------------// if ((Count > 7)&(k > 0)&((Count-(6+i))> 0)) st= radix[Count-(6+i)]; else if ((k > 0)|((Count > 7)&((Count-(6+i))== 0))) st= radix[Count-i]; else st= radix[0]; strcat(rd,st); //--------------------------------------------// } //--------------------------------------------------------------------------- void __fastcall TForm1::ReadBtnClick(TObject *Sender) { String val; int i,k,count; char rdix[10],rdix2[10],*st= ""; //---- Clear Thairead ----// for(i=0; i < maxL;i++) strcpy(thairead,st); //----------------- Read Bath Unit ---------------// count= Edit1->GetTextLen(); if (count > 0) { val= Edit1->Text; for(i= 1;i <= count;i++) { rdix[i-1]= val[i]; k= atoi(&rdix[i-1]); CheckThaiRead(count,i,k,thairead); } strcat(thairead,"บาท"); } //---------------- Read Stang Unit --------------// count= Edit2->GetTextLen(); if (count > 0) { val= Edit2->Text; for(i= 1;i <= count;i++) { rdix2[i-1]= val[i]; k= atoi(&rdix2[i-1]); CheckThaiRead(count,i,k,thairead); } if (val == "00") strcat(thairead,"ถ้วน"); else strcat(thairead,"สตางค์"); } Panel->Caption= thairead; } //--------------------------------------------------------------------------- void __fastcall TForm1::Edit1KeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { //------- Check Digit[0..9],Tab,Backspace Only -------// if (((Key >= 0x30)&(Key <= 0x39))| ((Key >= 0x60)&(Key <= 0x69))| ((Key >= 0x08)&(Key <= 0x09))) ReadBtn->Enabled= true; else { ClearBtnClick(Sender); ReadBtn->Enabled= false; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Edit2KeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { //------- Check Digit[0..9],Tab,Backspace Only -------// if (((Key >= 0x30)&(Key <= 0x39))| ((Key >= 0x60)&(Key <= 0x69))| ((Key >= 0x08)&(Key <= 0x09))) ReadBtn->Enabled= true; else { ClearBtnClick(Sender); ReadBtn->Enabled= false; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { exit(0); } //---------------------------------------------------------------------------