Hi Member 9983063,
This is not the way
TryParse()
works.
TryParse()
requires two parameters - one is the text to convert to integer, and the second is the output variable where it stores the converted value. The code you provided translates into:
if (Boolean > Boolean)
{
MessageBox.Show("Amount is less than bill amount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
This itself is wrong as a boolean can be compared with another boolean for '==' and '!=' only. Logically you cannot say 'if true is greater than false'. So this is one more compilation error along with the other compile error for
TryParse()
.
You can try the following approach:
int textBox00Val, txtTotalVal;
if (int.TryParse(textBox00.Text, out textBox00Val) == false)
{
MessageBox.Show("textBox00 value must be anumber.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (int.TryParse(txtTotal.Text, out txtTotalVal) == false)
{
MessageBox.Show("txtTotal value must be anumber.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (textBox00Val > txtTotalVal)
{
MessageBox.Show("Amount is less than bill amount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
............
............
What happens here is, you obtain the values in integers and then compare the integers.
@cvogt61457: I guess Member 9983063 meant a compile error, as the code in question will never compile (
TryParse()
must be provided two parameters, and a boolean cannot be compared to another boolean for 'greater than' operator).