.NET

Reply
Valued Mentor
gasty1001
Posts: 438
Registered: ‎04-11-2010
Message 11 of 16 (407 Views)

Re: Help needed with Triangle solution calculator in VB.NET

02-10-2012 11:42 AM in reply to: SteveHeather7776

Hi,

 

I insist that you are confused your self because the wrong positioned a,b,c values over the triangle in your screen grab. If  you have 3,4,5, then the value 5 MUST be over the hypotenuse, and NOT over a leg side. In other words where in the picture says "a" should be "c", and so with "c", given that  yo are solving the Pythagoras  in the standar form a*a+b*b=c*c. Other way just change the order of a,b,c in the formula.

 

Gaston Nunez

 

 

 

 

Active Member
SteveHeather7776
Posts: 8
Registered: ‎03-19-2009
Message 12 of 16 (390 Views)

Re: Help needed with Triangle solution calculator in VB.NET

02-10-2012 12:53 PM in reply to: gasty1001

There is nothing wrong with the pythagoras maths at all, it doesn't matter what you call the sides, they are just labels. It wouldn't matter if you called them side dog or side cat, it is the way in which you use them. If you look at the image I have attached you will see that it works ok for the pythagoras side of it.

Valued Mentor
jeff
Posts: 321
Registered: ‎05-12-2009
Message 13 of 16 (385 Views)

Re: Help needed with Triangle solution calculator in VB.NET

02-10-2012 01:12 PM in reply to: SteveHeather7776

I would redo the code to make easier, but looking real quick think about this section of code.

 

 If sideb = 0 Then
            sideb = Math.Sqrt((sidea * sidea) - (sidec * sidec))
            TextBoxSideb.Text = sideb

        ElseIf sidea = 0 Then
            sidea = Math.Sqrt((sideb * sideb) + (sidec * sidec))
            TextBoxSidea.Text = sidea

        ElseIf sidec = 0 Then
            sidec = Math.Sqrt((sidea * sidea) - (sideb * sideb))
            TextBoxSidec.Text = sidec
        End If

You are assuming that 2 sides will always have a value.

The sides really do not equal 0 you are using it as placeholder, might be better to take a different approach

You can also find your answers @ TheSwamp
Active Member
SteveHeather7776
Posts: 8
Registered: ‎03-19-2009
Message 14 of 16 (357 Views)

Re: Help needed with Triangle solution calculator in VB.NET

02-10-2012 07:24 PM in reply to: jeff

Thanks for your reply, I think it is very obvious that I don't know very much about VB programming, but I never proffessed too either. So I am asking for help on the solution please, in other words, what is the best way to code this calculator. As I mentioned earlier, I learn things by trial and error, and by seeing correct examples that I can then manipulate into my programmes.

 

Many thanks,

 

Steve

Active Member
SteveHeather7776
Posts: 8
Registered: ‎03-19-2009
Message 15 of 16 (355 Views)

Re: Help needed with Triangle solution calculator in VB.NET

02-10-2012 08:27 PM in reply to: SteveHeather7776

Hi guys,

 

I have changed all the lettering around as per your instructions, and added some extra code, and it works properly.

 

Thanks for all your help.

 

Steve.

 

New code below, and image attached:

 

Imports System.String
Imports System.Math
Public Class Form1
Dim angleA As Single = 90
Dim angleB As Single
Dim angleC As Single
Dim sidea As Single
Dim sideb As Single
Dim sidec As Single

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
Controls.Add(NumericUpDown1)

End Sub

Public Function isItNullString(ByVal value) As Boolean
If value = "" Then
Return True
Else
Return False
End If
End Function

Public Sub pythagoreanTheoremThings()

If sidec <> 0 And sidea <> 0 And sideb = 0 Then
sideb = Math.Sqrt((sidec * sidec) - (sidea * sidea))
TextBoxSideb.Text = sideb

ElseIf sideb <> 0 And sidea <> 0 And sidec = 0 Then
sidec = Math.Sqrt((sideb * sideb) + (sidea * sidea))
TextBoxSidec.Text = sidec

ElseIf sidec <> 0 And sideb <> 0 And sidea = 0 Then
sidea = Math.Sqrt((sidec * sidec) - (sideb * sideb))
TextBoxSidea.Text = sidea
End If
End Sub

Public Sub angleSums()

If angleC = 0 And angleB <> 0 Then
angleC = 180 - angleA - angleB
TextBoxAngleC.Text = angleC
End If

If angleB = 0 And angleC <> 0 Then
angleB = 180 - angleA - angleC
TextBoxAngleB.Text = angleB
End If
End Sub

Public Sub angleBasWorkingAngle()

'Angle B and side b known, find side c
If angleB <> 0 And sideb <> 0 Then
sidec = sideb / Sin(degreesToRadians(angleB))
TextBoxSidec.Text = sidec
End If

'Angle B and side a known, find side b
If angleB <> 0 And sidea <> 0 Then
sideb = sidea * Tan(degreesToRadians(angleB))
TextBoxSideb.Text = sideb
End If

'Angle B and side b known, find side a
If angleB <> 0 And sideb <> 0 Then
sidea = sideb / Tan(degreesToRadians(angleB))
TextBoxSidea.Text = sidea
End If

'Angle B and side b known, find side a
If angleB <> 0 And sidec <> 0 Then
sidea = sidec * Cos(degreesToRadians(angleB))
TextBoxSidea.Text = sidea
End If

End Sub

Public Sub findangleC()

If angleC = 0 Then
'cos
angleC = radiansToDegrees(Acos(sideb / sidec))
TextBoxAngleC.Text = angleC
End If

End Sub


Public Sub feedValues()

If Not isItNullString(TextBoxSideb.Text) Then
sideb = TextBoxSideb.Text
Else
sideb = 0
End If

If Not isItNullString(TextBoxSidea.Text) Then
sidea = TextBoxSidea.Text
Else
sidea = 0
End If

If Not isItNullString(TextBoxSidec.Text) Then
sidec = TextBoxSidec.Text
Else
sidec = 0
End If

If Not isItNullString(TextBoxAngleC.Text) Then
angleC = TextBoxAngleC.Text
Else
angleC = 0
End If

If Not isItNullString(TextBoxAngleB.Text) Then
angleB = TextBoxAngleB.Text
Else
angleB = 0
End If
End Sub

Public Function degreesToRadians(ByVal degrees As Double) As Double
Dim radians As Double
radians = (Math.PI * degrees) / 180
Return radians
End Function

Public Function radiansToDegrees(ByVal radians As Double) As Double
Dim degrees As Double
degrees = radians * (180 / Math.PI)
Return degrees
End Function


#Region " Calculate all Data "
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
For aaa As Integer = 0 To 2 'I just repeated this 6 times because I have a lot of processing power
'you can do it twice.
feedValues()

pythagoreanTheoremThings()

angleSums()

angleBasWorkingAngle()

findangleC()


Next

End Sub
#End Region


#Region " Clear all input boxes "
Public Sub ClearTextBox(ByVal root As Control)
For Each ctrl As Control In root.Controls
ClearTextBox(ctrl)
If TypeOf ctrl Is TextBox Then
CType(ctrl, TextBox).Text = String.Empty
End If
Next ctrl
End Sub
#End Region

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
ClearTextBox(Me)
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

New Member
grez_cute29
Posts: 1
Registered: ‎10-15-2012
Message 16 of 16 (269 Views)

Re: Help needed with Triangle solver

10-15-2012 02:24 AM in reply to: SteveHeather7776

..how to make triangle solver?where can i create like that one?i really need it because it is our project in trigonometry.thanks for the immediate respond=)

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community