Click here to Skip to main content
15,891,674 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi

i have a text box for the tax that text box should enter only 8 digit numbers and
each digit is multiplied with there weight factor and sum of those 8 product result should divide by 11 and if the remainder is zero it should show that the tax number is valid otherwise it should show the message invalid tax number...

for example i'm entering the below number in textbox
81 854 402:

1. (8x10) + (1x7) + (8x8) + (5x4) + (4x6) + (4x3) + (0x5) + (2x1)
2. 80 + 7 + 64 + 20 + 24 + 12 + 0 + 2 = 209
3. 209/11 = 19, remainder zero
4. The remainder is zero, so the number is valid.


may i know how to implement this logic in the c# application .....


Awaiting for your Earliest Reply...

with regards,
karthika
Posted
Comments
Sergey Alexandrovich Kryukov 25-Oct-11 1:42am    
Hard to understand what could be your problem? What did you try so far? What is difficult for you: whiting expressions, integer division/reminder operation, what?
--SA

C#
string txtnumber = txtNumber.Text.Replace(" ","");
string[] nums = txtnumber.ToCharArray();
int val=0;
for(int i=0; i< nums.Length; i++)
{
  val += ((int)(nums[i]-'0'))*WEIGHT[i];
}
 
Share this answer
 
Since it's a textbox you have the text property (a string). This should get you started (note: code not tested, but it should give you the idea):

C#
int sum = 0;
sum = sum + Convert.ToInt32(textbox.text.Substring(0,1))*10;

// continue with other digits, watching out for the spaces

int remainder = sum % 11; // modulo operator is % in C#
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900