–
Right Triangle
In a right triangle, the square of the length of the longest side is equal to the sum of the squares of the
lengths of the other two sides.
Write and test a Visual Basic program to
complete the following project,
determining whether a given triangle is “right” or not based on the lengths of its sides.
Code
o
Declare variables to hold the lengths of the three sides of a triangle. All should be
doubles.
o
Create an event handler for the click event in the first button. All the following activities
must take place within this event handler.
o
Reset the last bu
tton to its default appearance and text.
o
Input three values representing the lengths of three sides of a triangle in inches from
the three textboxes. Validate each of these values. If any input value is less than 0.1
inches, clear the corresponding textbox
and set the text in the label to indicate that the
offending value is too small.
o
Identify the longest side as the hypotenuse. Do no assume or require the user to identify
the longest side. Do this in code.
o
Calculate the expected length of the hypotenuse b
ased on the lengths of the 2 shorter
sides.
o
Compare the expected length of the hypotenuse to the length input by the user.
o
If the two lengths are the same, declare the triangle to be
“Right”, display the word
“Right” in the last button and set its
background color to green. Otherwise, declare the
triangle to be “Not Right”, display the words “Not Right” in the last button and set its
background color to red.
These are the instructions and I already have my buttons and labels in the right places. Here is the code that I have so far.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim A As Double Dim B As Double Dim C As Double A = TextBox1.Text B = TextBox.Text C = (A ^ 2 + B ^ 2) If Button2.Text = "Right" Then Button2.BackColor = Color.Green Else Button2.Text = "Not Right" Button2.BackColor = Color.Red End If
I have some errors that say: Reference to a non-shared member requires an object reference. And 'TextBox1' is not declared. It may be inaccessible due to its protection level.
I do not know how to fix these and I really don't understand what I am doing. I am just beginning, and we haven't learned about classes. Could someone look at this and give me some advice. Thanks!