Answered by:
Math Problem
Question

I have got this to give the right answer in excel but not in vb.
Did I do this wrong?
Excel I get 106.42
VB I get NaN
Try
Dim a1 As Double = TextBox1.Text
Dim b1 As Double = TextBox2.Text
Dim c1 As Double = TextBox3.Text
'ROUNDUP(SUM(SUM(2*B9)+1.57*SUM(B6+B3))+SUMSQ(B3B6)/SUM(4*B9),2)
Label9.Text = ((2 * c1) + 1.57 * (b1 + a1)) + Math.Sqrt(a1  b1) / (4 * c1)
Catch ex As Exception
End Try
Thanks
David
Answers
All replies


Scratch that, I see your problem.
SUMSQ returns the sum of the squares in the argument list (in this case, the square of B3B6).
In your VB code, you're finding the square root, which is not a number (well, technically an imaginary number) if b1 is greater than a1.

Dim a1 As Double = TextBox1.Text '=7
Dim b1 As Double = TextBox2.Text '=17
Dim c1 As Double = TextBox3.Text '=34
'ROUNDUP(SUM(SUM(2*B9)+1.57*SUM(B6+B3))+SUMSQ(B3B6)/SUM(4*B9),2)
Label9.Text = ((2 * c1) + 1.57 * (b1 + a1)) + Math.Sqrt(a1  b1) / (4 * c1)
Catch ex As Exception
End Try
I am confused, how do you get the square root?
Davids Learning

