0
txtNetPrice.Text = ((Convert.ToDouble(txtLength.Text) * 0) + Convert.ToDouble(txtPriceCut.Text)).ToString();

I'm getting error in this line.

please help.

4
Contributors
3
Replies
29
Views
4 Years
Discussion Span
Last Post by castajiz_2
1

When using Convert you will get that error if there is anything in the text string that is not a digit, a comma, or a period. An easy way to trap this error is to use the Double.TryParse method, on each string before you do your calculations, and use a messagebox to get the user to correct the input.

On a side note, since you're multiplying txtLength.Text by 0 it's redundant to have that in there.

0

To me your line of code reads as txtNetPrice.Text = 0 + ContxtPriceCut.Text;
Before the plus sign you are multiplying by zero. After the plus sign you are converting text to a double and you make again text of it with the ToString method.

0

I ve tried your code and it seems ok no matter if you type in textbox1 and textbox2 a integer for example 5 or a double 5.0 . Both will give the result. "Input string in the correct format will only show if you type in everything else but not a number. To be honest with you i have no clue why you are multyplying the double with zero because we all know the evaluation, but that s your choice. Also when doing such thing try to put more brackets because at the moment i also thought as ddanbe that you will convert the second double to text which would not make any sense, but no it will do the Tostring() after summing it up, still try to use brackets.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.