How do I get a proper answer using Visual Basic?

Posted on 2009-02-21
Medium Priority
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
  • 3
  • 2
LVL 15

Expert Comment

ID: 23700952
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

ID: 23700970
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

ID: 23701007
The code would be

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

some languages use ** instead of ^ for power operations

Author Comment

ID: 23701050
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

ChloesDad earned 2000 total points
ID: 23701098
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")

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

612 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