0

Dear Friends,
I want to compare two values of textboxs please, check my code

Int32 val11 = Convert.ToInt32(textBox4.Text);
                Int32 val22 = Convert.ToInt32(textBox10.Text);
                if(val11 >> val22)
                {                    
                        MessageBox.Show("Please, check Maximum Limit of Quantity.Quantity should be less tha fix Limit", "Limit", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                        textBox15.Focus();
                        textBox4.ForeColor = Color.Red;
                    }
                    else
                    {
                        textBox4.ForeColor = Color.Green;
                    }

I got error.

Error CS0029 Cannot implicitly convert type 'int' to 'bool'

4
Contributors
8
Replies
35
Views
3 Months
Discussion Span
Last Post by zebnoon1
0

What is that '>>' doing ther on line 3? Should be '>' I guess.
As an advise on the side, don't name your textboxes textbox15 whatever number. Give them meaningful names. Please do.

0

What if a user typed 'abc' instead of '123' in your textbox?
INT32.Convert would fail and you could embed it in a try-catch block and annoy your user with other messagboxes.
Another option is to use the method INT32.TryParse but with the same problems.
Best is to not allow the user to type in wrong characters, see example here.
After that you could safely use the suggestion of the Reverend amen.

0

Thanks friends,
I soved it.

            Int32 val11;
            Int32 val22;
            Int32.TryParse(textBox4.Text, out val11);
            Int32.TryParse(textBox10.Text, out val22);
            if (val11 < val22)
            {
                MessageBox.Show("Please, check Maximum Limit of Quantity.Quantity should be less tha fix Limit", "Limit", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                textBox15.Focus();
                textBox15.Clear();
                textBox10.ForeColor = Color.Red;
            }
            else
            {
                textBox10.ForeColor = Color.White;
            }
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.