I am trying to use the values from numericUpDown boxes.
With the execptoin of totalRunTime, all variables in this sample of code are from numericUpDown boxes.
I have tried declaring totalRunTime as an int, decimal, double, ect...
Am I missing something simple here?

 private void button1_Click(object sender, EventArgs e)
        {
            totalRunTime = (secondTemp.Value - startTemp.Value) / ramp1.Value + initialHold + 
                (finalTemp.Value - secondTemp.Value) / ramp2.Value + finalHold.Value;    
        }

Edited 3 Years Ago by Triryche

What error(s) are you getting? Post the exact error message(s).

Is secondTemp a textbox? If it is then you have to convert the Value to an int or float before using it in mathmatical equation.

Thanks for your reply.
Everything is from a NumericUpDown box, except for totalRunTime.

Error 1 Operator '+' cannot be applied to operands of type 'decimal' and 'System.Windows.Forms.NumericUpDown'

strangely enough this builds an runs fine when I comment out the rest of the equation.

  totalRunTime = (secondTemp.Value - startTemp.Value); // / ramp1.Value + initialHold + 
               // (finalTemp.Value - secondTemp.Value) / ramp2.Value + finalHold.Value;
            labelTotalRunTime.Text = totalRunTime.ToString();

Edited 3 Years Ago by Triryche

Why does this code build and run properly?
All I did was break the calculation into smaller pieces.

 private void button1_Click(object sender, EventArgs e)
        {
            //totalRunTime = (secondTemp.Value - startTemp.Value) / ramp1.Value + initialHold +
            //    (finalTemp.Value - secondTemp.Value) / ramp2.Value + finalHold.Value;

            totalRunTime = (secondTemp.Value - startTemp.Value);
            totalRunTime = totalRunTime / ramp1.Value + initialHold.Value;
            totalRunTime = totalRunTime + (finalTemp.Value - secondTemp.Value) / ramp2.Value + finalHold.Value;

            labelTotalRunTime.Text = totalRunTime.ToString();    
        }

Edited 3 Years Ago by Triryche

initialHold seems not to come from a Numeric updown and hence is not of type decimal if I'm correct.
This works when I tried it :

decimal totalRunTime = (10m - 5m) / 7m + 1m +
               (45m - 42m) / 1.5m + 1m;

Edited 3 Years Ago by ddanbe: addition

Indeed it is!!
Awesome!!
I was looking for that very type of typo (amoungst others) for a very long time.

Thanks for your help!!

This question has already been answered. Start a new discussion instead.