How to call a C# Class from a C# Form -


this class:

using system; using system.collections.generic; using system.text;  namespace num2wrd {  public class numbertoenglish {      public string changenumerictowords(double numb)     {         string num = numb.tostring();         return changetowords(num, false);     }      public string changecurrencytowords(string numb)     {         return changetowords(numb, true);     }      public string changenumerictowords(string numb)     {         return changetowords(numb, false);     }      public string changecurrencytowords(double numb)     {         return changetowords(numb.tostring(), true);     }      private string changetowords(string numb, bool iscurrency)     {         string val = "", wholeno = numb, points = "", andstr = "", pointstr = "";         string endstr = (iscurrency) ? ("only") : ("");         try         {             int decimalplace = numb.indexof(".");             if (decimalplace > 0)             {                 wholeno = numb.substring(0, decimalplace);                 points = numb.substring(decimalplace + 1);                 if (convert.toint32(points) > 0)                 {                     andstr = (iscurrency) ? ("and") : ("point");// separate whole numbers points/rupees                     endstr = (iscurrency) ? ("rupees " + endstr) : ("");                     pointstr = translaterupees(points);                 }             }             val = string.format("{0} {1}{2} {3}", translatewholenumber(wholeno).trim(), andstr, pointstr, endstr);         }         catch         {             ;         }         return val;     }      private string translatewholenumber(string number)     {         string word = "";         try         {             bool beginszero = false;//tests 0xx             bool isdone = false;//test if translated             double dblamt = (convert.todouble(number));             //if ((dblamt > 0) && number.startswith("0"))              if (dblamt > 0)             {//test 0 or digit 0 in nuemric                 beginszero = number.startswith("0");                 int numdigits = number.length;                 int pos = 0;//store digit grouping                 string place = "";//digit grouping name:hundres,thousand,etc...                 switch (numdigits)                 {                     case 1://ones' range                         word = ones(number);                         isdone = true;                         break;                     case 2://tens' range                         word = tens(number);                         isdone = true;                         break;                     case 3://hundreds' range                         pos = (numdigits % 3) + 1;                         place = " hundred ";                         break;                     case 4://thousands' range                     case 5:                     case 6:                         pos = (numdigits % 4) + 1;                         place = " thousand ";                         break;                     case 7://millions' range                     case 8:                     case 9:                         pos = (numdigits % 7) + 1;                         place = " million ";                         break;                     case 10://billions's range                         pos = (numdigits % 10) + 1;                         place = " billion ";                         break;                     //add case options above billion...                     default:                         isdone = true;                         break;                 }                 if (!isdone)                 {//if transalation not done, continue...(recursion comes in now!!)                     word = translatewholenumber(number.substring(0, pos)) + place + translatewholenumber(number.substring(pos));                     //check trailing zeros                     if (beginszero) word = " , " + word.trim();                 }                 //ignore digit grouping names                 if (word.trim().equals(place.trim())) word = "";             }         }             catch             {                 ;             }         return word.trim();     }      private string tens(string digit)     {         int digt = convert.toint32(digit);         string name = null;         switch (digt)         {             case 10:                 name = "ten";                 break;             case 11:                 name = "eleven";                 break;             case 12:                 name = "twelve";                 break;             case 13:                 name = "thirteen";                 break;             case 14:                 name = "fourteen";                 break;             case 15:                 name = "fifteen";                 break;             case 16:                 name = "sixteen";                 break;             case 17:                 name = "seventeen";                 break;             case 18:                 name = "eighteen";                 break;             case 19:                 name = "nineteen";                 break;             case 20:                 name = "twenty";                 break;             case 30:                 name = "thirty";                 break;             case 40:                 name = "fourty";                 break;             case 50:                 name = "fifty";                 break;             case 60:                 name = "sixty";                 break;             case 70:                 name = "seventy";                 break;             case 80:                 name = "eighty";                 break;             case 90:                 name = "ninety";                 break;             default:                 if (digt > 0)                 {                     name = tens(digit.substring(0, 1) + "0") + " " + ones(digit.substring(1));                 }                 break;         }         return name;     }      private string ones(string digit)     {         int digt = convert.toint32(digit);         string name = "";         switch (digt)         {             case 1:                 name = "one";                 break;             case 2:                 name = "two";                 break;             case 3:                 name = "three";                 break;             case 4:                 name = "four";                 break;             case 5:                 name = "five";                 break;             case 6:                 name = "six";                 break;             case 7:                 name = "seven";                 break;             case 8:                 name = "eight";                 break;             case 9:                 name = "nine";                 break;         }         return name;     }      private string translaterupees(string rupees)     {         string cts = "", digit = "", engone = "";         (int = 0; < rupees.length; i++)         {             digit = rupees[i].tostring();             if (digit.equals("0"))             {                 engone = "zero";             }             else             {                 engone = ones(digit);             }             cts += " " + engone;         }         return cts;     } } } 

form contains 2 textboxes (textbox1 , textbox2) , button(button1). want type amount in numbers in textbox1 , click on button. amount entered in numbers in textbox1 has converted text , appear in textbox2. functions convert in above c# class file. new student. can me in solving problem.

you have create object 'numbertoenglish' class , use in form1.cs way

 public partial class form1 : form     {         numbertoenglish neobj = new numbertoenglish();         public form1()         {             initializecomponent();          }          private void button1_click(object sender, eventargs e)         {             textbox2.text = neobj.changecurrencytowords(convert.todouble(textbox1.text));         }     } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -