Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# GimmeCode
I have following fields in the application as follows:
Eligibility Leave    36   Texbox1
Availed  Leave        3   Textbox2
Balance              33   Textbox3
When I type Availed Leave 3 in Textbox2, I want the output as 33 (Balance).
 private void txt_availed_TextChanged(object sender, EventArgs e)
        {
         
        }
Please send the code.
 
Regards,
Rao.
Posted 14-Nov-12 22:09pm
Edited 14-Nov-12 23:07pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

private void txt_availed_TextChanged(object sender, EventArgs e)         
{
            int eligibility = 0;
            int availed = 0;
            bool isValidValue = true;
 
            try
            {
                eligibility = int.Parse(textBox1.Text);
            }
            catch
            {
                isValidValue = false;
            }
 
            try
            {
                availed = int.Parse(textBox2.Text);
            }
            catch
            {
                isValidValue = false;
            }
 
            if (isValidValue)
            {
                textBox3.Text = (eligibility - availed).ToString();
            }
            else
            {
                textBox3.Text = "";
            }
        }
  Permalink  
Comments
Mohd. Mukhtar at 15-Nov-12 4:46am
   
Please avoid using these many try catch blocks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
            {
                textBox3.Text = (int.Parse(textBox1.Text) - int.Parse(textBox2.Text)).ToString();
            }
            else
            {
                textBox3.Text = "";
            }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try
            {
                textBox3.Text = (int.Parse(textBox1.Text) - int.Parse(textBox2.Text)).ToString();
            }
            catch
            {
                textBox3.Text = "";
            }
  Permalink  

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

  Print Answers RSS
0 Schatak 394
1 OriginalGriff 365
2 _Amy 115
3 Sergey Alexandrovich Kryukov 109
4 Andreas Gieriet 100
0 OriginalGriff 7,097
1 Sergey Alexandrovich Kryukov 5,623
2 Maciej Los 3,504
3 Peter Leow 3,373
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100