Thursday, September 6, 2018

Creating BMI Calculator Using VB.net


 First, design your interface as shown below:


Name the following:

  1. TextBox for weight - txtWeight
  2. TextBox for height - txtHeight
  3. Label for result - lblResult
  4. Button calculate - btnCalc
  5. 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.


Creating BMI Calculator Using VB.net  First, design your interface as shown below: Name the following: TextBox for weight - txtW...