How do I get a proper answer using Visual Basic?

Posted on 2009-02-21
Last Modified: 2013-12-14
How do I get my calculation button, btnConvert, to properly display the right formula for the Pythagorean theorem formula to be accurate?
Question by:probeg
    LVL 15

    Expert Comment

    I presume that you want to use the squared symbol as in superscript of 2.

    This is a standard character, so you should set the text property to something like


    It is character 0178, so press ALT down and then type 0178 while ALT is pressed

    Author Comment

    Well my theorem works but my answer is not doubling. When I try to sqr my answer in code, I get errors.
    LVL 15

    Expert Comment

    The code would be

    Asquared = ( B^2) + (C^2)
    A = ASquared ^ 0.5

    some languages use ** instead of ^ for power operations

    Author Comment

    I am using VB to write code. Here is my code so far.

    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
            If Theorem.Checked Then
                txtOutput.Text = Math.Pow(NUDradius.Value, 2) + Math.Pow(NUDheight.Value, 2)
            ElseIf Cylinder.Checked Then
                'cylinder volume
                txtOutput.Text = Math.Pow(NUDradius.Value, 2) * NUDheight.Value * Math.PI
            End If
        End Sub
    LVL 15

    Accepted Solution

    Your code for the hypothenuse is only calculating the sum of squares, it is not then taking the squareroot of the sum

    try something like this

    Dim SumofSquares as double =  Math.Pow(NUDradius.Value, 2) + Math.Pow(NUDheight.Value, 2)
     txtOutput.Text =Math.pow(SumofSquares,0.5).tostring("0.000")

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now