Calculator Help 05-25-2014, 06:19 PM
#1
Hey guys! I'm in the process of creating a calculator with added functionality of figuring out the area, perimeter, and length of a square (and hopefully more polygons) given a single one of the above.
It works fine if I give it the length, but if I give it the area or perimeter it gives me 0 for each of my answers. I'm relatively new to VB.NET (about a week ago), and I'm looking for criticism. Here's my code:
It works fine if I give it the length, but if I give it the area or perimeter it gives me 0 for each of my answers. I'm relatively new to VB.NET (about a week ago), and I'm looking for criticism. Here's my code:
Code:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim area As Single
Dim peri As Single
Dim length As Single
If sqarea.Text = "" Then
sqarea.Text = "0"
End If
If sqper.Text = "" Then
sqper.Text = "0"
End If
If sqlth.Text = "" Then
sqlth.Text = "0"
End If
area = sqarea.Text
peri = sqper.Text
length = sqlth.Text
area = length * length
sqarea.Text = (area & " units²")
peri = length * 4
sqper.Text = (peri & " units")
If sqarea.Text = "" Then
length = peri / 4
sqlth.Text = (length & " units")
End If
If sqper.Text = "" Then
length = Math.Sqrt(area)
sqlth.Text = (length & " units")
End If
End Sub