|
if (txtdisc.Text ==null)
{
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
Double txtdisc22013 = Convert.ToDouble(txtdisc.Text);
txttot22013 = txttot22013 - txtdisc22013;
txttot.Text = txttot22013.ToString();
}
else
{
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
txttot.Text = txttot22013.ToString();
}
if (txtvat.Text == null)
{
MessageBox.Show("Enter Vat Amount");
}
else
{
Double txtvat22013 = Convert.ToDouble(txtvat.Text);
txtvat22013 = txtvat22013 / 100;
txtvat22013 = txtvat22013 * txttot22013;
Double txtvatinclu22013 = txtvat22013 + txttot22013;
txtvatinclu.Text = txtvatinclu22013.ToString();
}
|
|
|
|
|
There's no loop in that code anywhere. What's your question?
BTW - you shouldn't use Convert.To... to convert doubles - try Double.TryParse instead as it's much more tolerant of invalid values.
|
|
|
|
|
You REALLY need to pick up a beginners book on C# and work through it. There is no loop in any of this code and if statements are not cosidered loops at all.
TextBox.Text will NEVER return null . It's either going to be something that the user typed in or String.Empty , but never null .
|
|
|
|
|
if (txtdisc.Text == null)
{
..
Double txtdisc22013 = Convert.ToDouble(txtdisc.Text);
translates into
Double txtdisc22013 = Convert.ToDouble(null);
That does not make much sense.
|
|
|
|
|
It will never get that far as txtdisc.Text can never be null as it returns a string.
the OP should of tested it either by
if(string.IsNullorEmpty(txtdic.Text) != true)
{
}
or
if(txtdisc.Text != string.Empty)
{
}
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Hi
First, like others mentioned, "if" and "else" are conditional statements, they are not loop.
Second, the textbox will return empty if it has no value assigned to it, so checking for null is redundant.
Third, this is a coding horror!
if (txtdisc.Text ==null) This check is redundant therefore the calls below will never be executed.
{
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
Double txtdisc22013 = Convert.ToDouble(txtdisc.Text); Converting a null to a nullable Double will 0.0;
txttot22013 = txttot22013 - txtdisc22013; (Some value – 0.0)
txttot.Text = txttot22013.ToString();
}
else
{
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
txttot.Text = txttot22013.ToString(); The value of "txttot22013" in the else conditions is no different to the one in if condition.
}
if (txtvat.Text == null)
{
MessageBox.Show("Enter Vat Amount"); This will never be called.
}
else
{
Double txtvat22013 = Convert.ToDouble(txtvat.Text); Possible exception.
txtvat22013 = txtvat22013 / 100;
txtvat22013 = txtvat22013 * txttot22013;
Double txtvatinclu22013 = txtvat22013 + txttot22013;
txtvatinclu.Text = txtvatinclu22013.ToString();
}
If I rewrite your code, it may as follows:
txttot22013 = txtpr22013 + txtpr22014 + txtpr22015 + txtpr22016 + txtpr22017;
txttot.Text = txttot22013.ToString();
if (string.IsNullOrEmpty(txtvat.Text))
{
MessageBox.Show("Enter Vat Amount");
}
else
{
double txtvat22013;
if (Double.TryParse(txtvat.Text, txtvat22013))
{
Double txtvatinclu22013 = (txtvat22013 * txttot22013 / 100) + txttot22013;
txtvatinclu.Text = txtvatinclu22013.ToString();
}else
{
MessageBox.Show("Enter Valid Vat Amount");
}
}
Regards
Jegan
|
|
|
|
|
thanks a lot for suggestion but "loop" is my mistake i knw its a conditional statements ... thanks a lot for every one coz ur my seniors u have rights correct me....
|
|
|
|
|
Does that include correcting your English that you typed?
|
|
|
|