First, design your interface as shown below:
Name the following:
- TextBox for weight - txtWeight
- TextBox for height - txtHeight
- Label for result - lblResult
- Button calculate - btnCalc
- Button reset - btnReset
Then, the source code:
Public Class Form1
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Call Calculate()
End Sub
Private Sub Calculate()
Dim numWeight As Integer
Dim numHeight As Integer
Dim BMI As Double
lblResult.Text = ""
numHeight = Single.Parse(txtHeight.Text)
numWeight = Single.Parse(txtWeight.Text)
BMI = numWeight / ((numHeight / 100) ^ 2)
Select Case BMI
Case Is <= 18.5
lblResult.Text = "You are Underweight"
Case Is <= 24.9
lblResult.Text = "You are Normal Weight"
Case Is <= 29.9
lblResult.Text = "Overweight"
Case Else
lblResult.Text = "Obese"
End Select
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtHeight.Text = ""
txtWeight.Text = ""
lblResult.Text = "RESULT"
End Sub
End Class
Hope that this will help you. Thank you for reading.
No comments:
Post a Comment