Calculate Area of Triangle with VB6
This is a quick example of how to implement a basic math formula within your program.
The example project only contains one form, with three fields and a button:
All three fields need to be populated with values, which is checked for in the code. Also, this example will only let you enter numeric values in the fields, in order to prevent errors which would be generated by entering other (or invalid) characters.
Given the length of all three sides of a triangle, along with the use of Herons formula, the program will calculate the total area of the triangle.
Just a little something to get some folks started in the right direction on their homework assignments. ;)
Webmaster Note
This article has been updated to reflect the correct outcome. The previous version of the article made use of an incomplete process to find the area of a triangle, and skipped the use of Herons formula.
Herons formula states:
AREA = sqrt(s(s-a)(s-b)(s-c))
Where:
s = SemiPerimeter of the triangle, and a, b, and c are the lengths of the individual sides.
Thanks to an angry math nerd in middle America, who has a penchant for irate rants, for pointing out the mistake. The code has been updated, and the author responsible for the error has been beaten to within an inch of his life.
To the angry old man, I hope this sates your quest for accuracy. Now that the author and myself have fixed the error, you have all the time in the world to fix dotnetplayground. That is, unless you are dedicating your life to harassing random websites.
About this post
Posted: 2019-01-02
By: vb6boy
Viewed: 2,127 times
Categories
Attachments
TriangleArea.zip
Posted: 4/16/2019 3:04:47 PM
Size: 1,932 bytes
Loading Comments ...
Comments
You must be logged in to make a comment.
AnonymousCoward posted this comment on 2021-04-30:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = 3.14 * TextBox1.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox5.Text = TextBox3.Text * TextBox4.Text
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim a As Integer = TextBox6.Text
Dim b As Integer = TextBox7.Text
Dim c As Integer = TextBox8.Text
Dim s As Double = (a + b + c) / 2
Dim findarea As Double = Math.Sqrt(s * (s - a) * (s - b) * (s - c))
TextBox9.Text = findarea
End Sub
End Class