# Visual Basic 2010 Pythagorean Theorem

Page 1 of 1

## 10 Replies - 8750 Views - Last Post: 08 November 2011 - 11:32 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=254708&amp;s=fdac5f2877f552866e0cbd14b7be6ac8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 h1z1

• New D.I.C Head

Reputation: 2
• Posts: 24
• Joined: 21-September 11

# Visual Basic 2010 Pythagorean Theorem

Posted 07 November 2011 - 10:57 AM

Hi, me again. This morning we started doing a pythagorean theorem which basicly will convert a set of numbers into the answer. The theorem is a² + b² = c²
Basicly I wan't it to fidn the C in a triangle.
Some thing I were told that we should use are :
``` Dim a As Double
Dim b As Double
Dim c As Double

```

We were also told that we shoudl use
``` Math.sqrt
```

The project was said to be 10 lines of code.
Here are pictures of what I have so far:

Thanks for the help

Is This A Good Question/Topic? 0

## Replies To: Visual Basic 2010 Pythagorean Theorem

### #2 lordofduct

• I'm a cheeseburger

Reputation: 2606
• Posts: 4,735
• Joined: 24-September 10

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 07 November 2011 - 11:03 AM

re-order the formula to be a function of a and b:

```c = f(a,B)/>
f(a,B)/> = sqrt(a^2 + b^2)

```

solve

done

This post has been edited by lordofduct: 07 November 2011 - 11:04 AM

Was This Post Helpful? -1

### #3 Tryparse

• D.I.C Head

Reputation: 80
• Posts: 193
• Joined: 20-April 10

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 07 November 2011 - 11:09 AM

K, you state the theorem (a² + b² = c²), but your form shows adding 3 textboxes to get a value.
Anyway, you state that you need to find C. How do you do that? You square A and B, add them together, and get the square root of the result.
You can't just call sqrt(), it's a static method. Here's some proper function calls to get you started:
```Math.Pow(a, 2)
Math.Pow(b, 2)
c = Math.Sqrt(whatNeedsToBeHere)
```

Was This Post Helpful? 1

### #4 h1z1

• New D.I.C Head

Reputation: 2
• Posts: 24
• Joined: 21-September 11

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 07 November 2011 - 11:11 AM

I actually just tried something insanely stupid. I'll post back later tonight because I've gotta get to class.
Was This Post Helpful? 0

### #5 h1z1

• New D.I.C Head

Reputation: 2
• Posts: 24
• Joined: 21-September 11

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 10:38 AM

Alright so when I made the above post I thought I figured it out. Here is what I did:
```Public Class Form1
Dim a As Double
Dim b As Double
Dim c As Double
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub calcbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcbtn.Click
lbl2.Text = Math.Sqrt(tb1a.Text + tb2b.Text)
End Sub

Private Sub resetbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetbtn.Click
tb1a.Text = ""
tb2b.Text = ""
lbl2.Text = ""
End Sub
End Class

```

But this didn't work. I can't seem to figure this one out. I don't see how I'll use the Double Strings and such, any ideas?
Was This Post Helpful? 0

### #6 h1z1

• New D.I.C Head

Reputation: 2
• Posts: 24
• Joined: 21-September 11

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 10:57 AM

Update: Tried something new looking at Treyparse's code
```Public Class Form1
Dim a As Double

Dim b As Double
Dim c As Double

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub calcbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcbtn.Click
Math.Pow(a, 2)
Math.Pow(b, 2)

c = Math.Sqrt(a ^ 2 + b ^ 2)

lbl2.Text = c
End Sub

Private Sub resetbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetbtn.Click

End Sub
End Class

```

Was This Post Helpful? 0

### #7 Tryparse

• D.I.C Head

Reputation: 80
• Posts: 193
• Joined: 20-April 10

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 11:01 AM

Now you're on the right track, except you don't just call Math.Pow(a, 2) -- it's a function, it returns a value. And I'd forgotten about the ^ operator, so you actually don't need to use Math.Pow().

This post has been edited by Tryparse: 08 November 2011 - 11:04 AM

Was This Post Helpful? 1

### #8 h1z1

• New D.I.C Head

Reputation: 2
• Posts: 24
• Joined: 21-September 11

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 11:02 AM

Yeah sorry, I posted an update saying I did look at your post
Was This Post Helpful? 0

### #9 Tryparse

• D.I.C Head

Reputation: 80
• Posts: 193
• Joined: 20-April 10

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 11:05 AM

Oh goodie, we're posting at the same time. I modified my response in response to your response (anyone else sense a "yo dawg" coming on here?).
Was This Post Helpful? 1

### #10 h1z1

• New D.I.C Head

Reputation: 2
• Posts: 24
• Joined: 21-September 11

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 11:10 AM

I was kinda useing your code as a refrence, do you mind posting it back up?

Update again: I tried using Treyparse's updated code but when I did 3 and 4 I got 6.5 and I'm sure that's not right. Here's some code:
```Public Class Form1
Dim a As Double

Dim b As Double
Dim c As Double

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub calcbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcbtn.Click
a = Math.Pow(Double.Parse(tb1a.Text), 2)
b = Math.Pow(Double.Parse(tb2b.Text), 2)
c = Math.Sqrt(tb2b.Text + tb1a.Text)
lbl2.Text = c

End Sub

Private Sub resetbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetbtn.Click

End Sub
End Class

```

Was This Post Helpful? 0

### #11 Tryparse

• D.I.C Head

Reputation: 80
• Posts: 193
• Joined: 20-April 10

## Re: Visual Basic 2010 Pythagorean Theorem

Posted 08 November 2011 - 11:32 AM

No! Bad! You're taking the STRING values in the textboxes and concatenating them (you end up with 43 in the case of 3 & 4), then trying to get the square root of that.
```c = Math.Sqrt(tb2b.Text + tb1a.Text)
'needs to be
c = Math.Sqrt(a + B)/>

'If we really wanna get crazy, here it all is in 1 line
lbl2.Text = Math.Sqrt(Math.Pow(Double.Parse(tb1a.Text), 2) + Math.Pow(Double.Parse(tb2b.Text), 2)).ToString()
'Writing one-liners like that is fun and all, but keep in mind that
'anyone who has to maintain it after you will stab you in the eye.

```

This post has been edited by Tryparse: 08 November 2011 - 11:38 AM

Was This Post Helpful? 1

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}