none
Math Problem RRS feed

  • 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(B3-B6)/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

    Thursday, March 20, 2008 8:41 PM

Answers

  •  

    If you're wanting to get the square root in excel, replace SUMSQ with SQRT.

     

    If you're wanting to get the square in VB, use the following code:

     

    Code Snippet

    Label9.Text = ((2 * c1) + 1.57 * (b1 + a1)) + (a1 - b1)^2 / (4 * c1)

     

     

    Thursday, March 20, 2008 9:47 PM

All replies

  • Provide the values you plugged in.

    Thursday, March 20, 2008 9:23 PM
  • Scratch that, I see your problem.

     

    SUMSQ returns the sum of the squares in the argument list (in this case, the square of  B3-B6).

     

    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.

     

    Thursday, March 20, 2008 9:31 PM
  • 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(B3-B6)/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

     

    Thursday, March 20, 2008 9:35 PM
  •  

    If you're wanting to get the square root in excel, replace SUMSQ with SQRT.

     

    If you're wanting to get the square in VB, use the following code:

     

    Code Snippet

    Label9.Text = ((2 * c1) + 1.57 * (b1 + a1)) + (a1 - b1)^2 / (4 * c1)

     

     

    Thursday, March 20, 2008 9:47 PM
  • Thanks Chris

     

    The ^ did the trick.

     

    Davids Learning

     

     

     

    Thursday, March 20, 2008 10:09 PM