VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Computes the type / properties of a Triangle. A good program for beginners.

by BasuDip (5 Submissions)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 21st July 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Computes the type / properties of a Triangle. A good program for beginners.

Rate Computes the type / properties of a Triangle. A good program for beginners.



Private Function TriangleExist(ByVal sideA As Long, _
                               ByVal sideB As Long, _
                               ByVal sideC As Long) As Boolean
If sideA + sideB > sideC And sideB + sideC > sideA And sideC + sideA > sideB Then
TriangleExist = True
Else
TriangleExist = False
End If
End Function
Private Function AreaOfTriangle(ByVal sideA As Long, _
                                ByVal sideB As Long, _
                                ByVal sideC As Long) As Double
If TriangleExist(sideA, sideB, sideC) = False Then Exit Function
S = (sideA + sideB + sideC) / 2
AreaOfTriangle = Sqr(S * (S - sideA) * (S - sideB) * (S - sideC))
End Function
Private Sub CirclesTriangle(ByVal sideA As Long, _
                            ByVal sideB As Long, _
                            ByVal sideC As Long, _
                            Optional ByRef InCircle As Single = 0, _
                            Optional ByRef CircumCircle As Single = 0)
Dim tArea As Double
tArea = AreaOfTriangle(sideA, sideB, sideC)
InCircle = tArea / S
CircumCircle = (sideA * sideB * sideC) / (4 * tArea)
End Sub
Private Sub typeOfTriangle(ByVal sideA As Long, _
                           ByVal sideB As Long, _
                           ByVal sideC As Long, _
                           Optional ByRef typAngle As String, _
                           Optional ByRef typSide As String)
Dim maxSide As Long, minSide As Long, otherSide As Long
    If sideA = sideB And sideB = sideC Then
        typSide = "Equilateral"
    ElseIf sideA = sideB Or sideB = sideC Or sideC = sideA Then
        typSide = "Isosceles"
    Else
        typSide = "Scalene"
    End If
S = (sideA + sideB + sideC) / 2
    If sideA >= sideB And sideA >= sideC Then
        maxSide = sideA
        If sideB > sideC Then
            minSide = sideC:    otherSide = sideB
        Else
            minSide = sideB:    otherSide = sideC
        End If
    ElseIf sideB >= sideC And sideB >= sideA Then
        maxSide = sideB
        If sideA > sideC Then
            minSide = sideC: otherSide = sideA
        Else
            minSide = sideA: otherSide = sideC
        End If
    Else
        maxSide = sideC
        If sideA > sideB Then
            minSide = sideB: otherSide = sideA
        Else
            minSide = sideA: otherSide = sideB
        End If
    End If
If maxSide * maxSide = minSide * minSide + otherSide * otherSide Then
    typAngle = "RightAngled"
ElseIf maxSide * maxSide > minSide * minSide + otherSide * otherSide Then
    typAngle = "ObtuseAngled"
ElseIf maxSide * maxSide < minSide * minSide + otherSide * otherSide Then
    typAngle = "AcuteAngled"
End If
End Sub

Private Sub cmdCompute_Click()
Dim a As Long, b As Long, c As Long, msgStr As String, _
    Ir As Single, Cr As Single, typeAngle As String, typeSide As String
a = CLng(txtVal1.Text): b = CLng(txtVal2.Text): c = CLng(txtVal3.Text) 'Input
If TriangleExist(a, b, c) = False Then
msgStr = "The sides do not form a Triangle."
GoTo endLine
End If
Call CirclesTriangle(a, b, c, Ir, Cr)
Call typeOfTriangle(a, b, c, typeAngle, typeSide)
msgStr = "The Triangle is " & typeSide & " and " & typeAngle & vbNewLine & _
    "The AREA of the triangle is " & FormatNumber(AreaOfTriangle(a, b, c), 4) & " sq. unit;" & vbNewLine & _
    "InCircle radius is " & FormatNumber(Ir, 4) & " unit," & vbNewLine & "CircumCircle radius is " & FormatNumber(Cr, 4) & " unit."
endLine:
    MsgBox msgStr, vbInformation, "Triangle Info"
End Sub

Download this snippet    Add to My Saved Code

Computes the type / properties of a Triangle. A good program for beginners. Comments

No comments have been posted about Computes the type / properties of a Triangle. A good program for beginners.. Why not be the first to post a comment about Computes the type / properties of a Triangle. A good program for beginners..

Post your comment

Subject:
Message:
0/1000 characters