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;    
        }

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();

Value is of type Decimal class -- it's not a numeric type. You will have to use some of the methods of the Decimal class to add and subtract two Decimal objects.

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();    
        }

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;

initialHold is the name property of a NumericUpDown box.

So initialHold without .Value is a typo?

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

Thanks for your help!!

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.