Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
double days = Convert.ToDouble(textbox1.Text);
           double sundays = Convert.ToDouble(textbox2.Text);
           double a = Convert.ToDouble(textbox3.text);
           textbox4.text = Convert.ToDouble((a / days) * sundays).ToString();



i try this code it is working but when i press clear button error occurs

the input string was not in correct format.in the first line.


clear button code as follows

C#
textbox1.text = "";
           textbox2.text = "";
           textbox3.text = "";
           textbox4.text = "";



please send the code. help me.
Posted
Updated 9-Jul-12 23:34pm
v2
Comments
S.Faizan.Ali 10-Jul-12 5:41am    
where you have put the above code? I mean behind which event?

1 solution

Is your conversion code running after clearing the textboxes too.

I think after clearing the textbox the conversion is happening and is giving exception.

I suggest use of Double.TryParse just to make it little robust. and before trying to convert check whether the textboxes are empty or filled with some value.

i.e.

C#
if(textbox1.Text != string.Empty)
{
  double days = Double.TryParse(textbox1.Text);
}
 
Share this answer
 
Comments
AshishChaudha 10-Jul-12 7:15am    
my 5!

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