Ub3r-L33ch
Member
- Joined
- Sep 20, 2005
- Messages
- 11
- Programming Experience
- Beginner
Ok so this goes back to a POST I made before about calculating BMI based on height and weight entered. Well now I have to add to that project.
One part is that I have to include radio buttons to select and if you select the right one with the number range that is equal to the result from the BMI calculation. For instance:
You enter 200 in weight and 74 in inches. The result from the calculation is 25.68, if you selected the radio button 25 to 29.9 you would get a message "You guessed your BMI correctly"
Here's the code I have so far from the previous project with a few new things I added for this one:
'Option Explicit and Strict have to be on in this project
Option Strict On
Option Explicit On
Public Class bmiForm
Inherits System.Windows.Forms.Form
Windows Form Designer Generated Code
'Declare the Constant
Const BMI_Integer As Integer = 703I
Private Sub buttonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonClear.Click
'Clears the Form and sets focus to Weight text box
textWeight.Clear()
textHeight.Clear()
'Clears the radio Buttons
radButton18.Checked = False
radButton18_24.Checked = False
radButton25_29.Checked = False
radButton30.Checked = False
With textWeight
.Clear()
.Focus()
End With
End Sub
Private Sub buttonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonExit.Click
'Exits the Form
Me.Close()
End Sub
Private Sub buttonCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCalc.Click
'Calculates the BMI
'Declare Variables
Dim Weight As Double = Val(textWeight.Text)
Dim Height As Double = Val(textHeight.Text)
Dim BMI As Double = Weight / Height ^ 2 * 703
'Show result with formatting
labelResult.Text = String.Format("{0:n2}", BMI)
'Catch Errors in Weight Text Box
Try
Weight = Integer.Parse(textWeight.Text)
Catch err As FormatException
MessageBox.Show("Non-numeric Data entered in Weight.", "Error", MessageBoxButtons.OK)
End Try
'Catch Errors in Height Text Box
Try
Height = Integer.Parse(textHeight.Text)
Catch err As FormatException
MessageBox.Show("Non-numeric Data entered in Height.", "Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub checkBoxInfo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBoxInfo.CheckedChanged
'Displays additional information when CheckBox is checked
If checkBoxInfo.Checked Then
checkBoxInfo.Text = "Body mss index (BMI) is a measurement based on height and weight as it realtes to body fat. The relationship differs with age and gender. For example, women are more likely to have a higher percent of body fat than men for the same BMI. On average, older people may have more body fat than younger adults with the same BMI."
Else
checkBoxInfo.Text = "Check the box for additional information"
End If
End Sub
End Class
Sorry to bug you guys with such simple crap, hopefully it wont take more than a few minutes to explain to me what I need to do.
Thanks for any help.
One part is that I have to include radio buttons to select and if you select the right one with the number range that is equal to the result from the BMI calculation. For instance:
You enter 200 in weight and 74 in inches. The result from the calculation is 25.68, if you selected the radio button 25 to 29.9 you would get a message "You guessed your BMI correctly"
Here's the code I have so far from the previous project with a few new things I added for this one:
'Option Explicit and Strict have to be on in this project
Option Strict On
Option Explicit On
Public Class bmiForm
Inherits System.Windows.Forms.Form
Windows Form Designer Generated Code
'Declare the Constant
Const BMI_Integer As Integer = 703I
Private Sub buttonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonClear.Click
'Clears the Form and sets focus to Weight text box
textWeight.Clear()
textHeight.Clear()
'Clears the radio Buttons
radButton18.Checked = False
radButton18_24.Checked = False
radButton25_29.Checked = False
radButton30.Checked = False
With textWeight
.Clear()
.Focus()
End With
End Sub
Private Sub buttonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonExit.Click
'Exits the Form
Me.Close()
End Sub
Private Sub buttonCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCalc.Click
'Calculates the BMI
'Declare Variables
Dim Weight As Double = Val(textWeight.Text)
Dim Height As Double = Val(textHeight.Text)
Dim BMI As Double = Weight / Height ^ 2 * 703
'Show result with formatting
labelResult.Text = String.Format("{0:n2}", BMI)
'Catch Errors in Weight Text Box
Try
Weight = Integer.Parse(textWeight.Text)
Catch err As FormatException
MessageBox.Show("Non-numeric Data entered in Weight.", "Error", MessageBoxButtons.OK)
End Try
'Catch Errors in Height Text Box
Try
Height = Integer.Parse(textHeight.Text)
Catch err As FormatException
MessageBox.Show("Non-numeric Data entered in Height.", "Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub checkBoxInfo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBoxInfo.CheckedChanged
'Displays additional information when CheckBox is checked
If checkBoxInfo.Checked Then
checkBoxInfo.Text = "Body mss index (BMI) is a measurement based on height and weight as it realtes to body fat. The relationship differs with age and gender. For example, women are more likely to have a higher percent of body fat than men for the same BMI. On average, older people may have more body fat than younger adults with the same BMI."
Else
checkBoxInfo.Text = "Check the box for additional information"
End If
End Sub
End Class
Sorry to bug you guys with such simple crap, hopefully it wont take more than a few minutes to explain to me what I need to do.
Thanks for any help.