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

I'm getting error in this line.

please help.

Recommended Answers

All 3 Replies

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.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.