Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Triangle Information Viewer
Author:
BasuDip
Website:
http://www.geocities.com/basudip_in/vb6code/
Submitted:
7/21/2006
Version:
VB6
Compatibility:
VB6
Category:
Mathematics
Views:
8619
The program helps to compute the area of a triangle, radius of in-circle and circum-circle, and the type of the triangle. I recommend the program for VB learners.
Declarations:
Place 3 text box(txtVal1,2,3) for input and a command button (cmdCompute) on the VB form
Code:
Private S As Single 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
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement