Jump to content

Archived

This topic is now archived and is closed to further replies.

Freekiller #3

Help me finish my VB.net code

Recommended Posts

Hey guys i'm trying to code the functions for this BMI calculator and I can't get the result to display in my number4Label control I suspect that i am not entering the statement for the formula correctly ( someone pls halp)

 

'BMI CALCULATOR
Public Class BMI
    ' Shows BMI index Information upon form loading.
    Private Sub BMI_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        number4TextBox.Text = "BMI VALUES" & vbCrLf _
           & "Underweight: less than 18.5" & vbCrLf _
           & "Normal:      between (18.5 and 24.9)" & vbCrLf _
           & "Overweight:  between (25 and 29.9)" & vbCrLf _
           & "Obese:       30 or greater"
    End Sub

    ' Click event; calculates BMI for user.
    Private Sub number1Button_Click(sender As Object, e As EventArgs) Handles number1Button.Click
        Dim number1 As Integer ' weight in pounds
        Dim number2 As Integer ' height in inches
        Dim result As Integer ' BMI result

        number1 = number1TextBox.Text ' Weight entered
        number2 = number2TextBox.Text ' Height entered
        result = (number1 * 703) \ number2 ^ 2 ' Weight in pounds * 703 \ (height in inches) ^ 2 = Bmi Result
        number4Label = result ' diplays the BMI

    End Sub


End Class

Share this post


Link to post
Share on other sites

number4label.text = result

Also you might want to start being more specific when naming objects and variables since it makes things a lot easier when you make more complex projects later on. https://msdn.microsoft.com/en-us/library/aa263493(v=vs.60).aspxIn my class we always used these prefixes followed by the name so lblResult would replace number4label and instead of number# use weight / height

'BMI CALCULATOR

Public Class BMI

' Shows BMI index Information upon form loading.

Private Sub BMI_Load(sender As Object, e As EventArgs) Handles MyBase.Load

txtBMIValues.text = "BMI VALUES" & vbCrLf _

& "Underweight: less than 18.5" & vbCrLf _

& "Normal: between (18.5 and 24.9)" & vbCrLf _

& "Overweight: between (25 and 29.9)" & vbCrLf _

& "Obese: 30 or greater"

End Sub

' Click event; calculates BMI for user.

Private Sub btnCalculateBMI_Click(sender As Object, e As EventArgs) Handles btnCalculateBMI.Click

Dim weight As Integer = txtWeight.text ' weight in pounds

Dim height As Integer = txtHeight.text ' height in inches

Dim result As Integer ' BMI result

result = (weight * 703) \ height ^ 2

lblResult.text = result ' diplays the BMI

End Sub

End Class

Share this post


Link to post
Share on other sites

×
×
  • Create New...