Jess
February 10th, 2013, 12:14 AM
Solved.
//..
I'm creating a BMI calculator for my visual basic class. I'm nearly done.
' Jessica Chen (jzc22)
' This program will calculate the BMI (Body Mass Index) given the inputed
' user weight and height.
' uses:
' lblWeight - Label - prompt for where user should enter weight, in kilograms
' lblHeight - Label - prompt for where user should enter height, in meters
' weightTB - TextBox - used to get user input for weight
' heightTB - TextBox - used to get user input for height
' calcBtn - Button - used by user to start task of calulating the BMI
' outputTB - TextBox - ReadOnly(True),Multiline(True),VerticalScroll - used to show user
' result of calculation and any warnings
Option Strict On
Option Explicit On
Option Infer Off
Option Compare Binary
Public Class bmiCalculator
Dim counter As Integer = 0
Private Sub calcBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcBtn.Click
counter += 1
Dim weight As Integer
weight = CInt(weightTB.Text)
Dim height As Integer
height = CInt(heightTB.Text)
Dim result As Double
If weight > 0 And height > 0 Then
result = (weight / height ^ 2)
outputTB.AppendText("Your BMI is " & CDbl(result) & "." & vbCrLf)
If result < 15.0 Then
outputTB.AppendText("Warning: Dangerous underweight condition!" & vbCrLf)
ElseIf result > 40.0 Then
outputTB.AppendText("Warning: Dangerous overweight condition!" & vbCrLf)
End If
If result >= 15.0 And result < 16.0 Then
outputTB.AppendText("Severely underweight" & vbCrLf)
End If
If result >= 16.0 And result < 18.5 Then
outputTB.AppendText("Underweight" & vbCrLf)
End If
If result >= 18.5 And result < 25.0 Then
outputTB.AppendText("Normal" & vbCrLf)
End If
If result >= 25.0 And result < 30.0 Then
outputTB.AppendText("Overweight" & vbCrLf)
End If
If result >= 30.0 And result < 35.0 Then
outputTB.AppendText("Moderately obese" & vbCrLf)
End If
If result >= 35.0 And result < 40.0 Then
outputTB.AppendText("Severely obese" & vbCrLf)
End If
outputTB.AppendText("Number of BMI Calculations: " & CStr(CDbl(counter)) & vbCrLf)
Else
If weight < 0 And height < 0 Then
outputTB.AppendText("Inputed height or weight not valid!" & vbCrLf)
End If
End If
End Sub
End Class
All I need help on is how to get the output text to replace the current text if I put in new values. In other words, if I put in 65 for weight and 1.2 for height and get a result, how do I get it to clear when I put in new values?
//..
I'm creating a BMI calculator for my visual basic class. I'm nearly done.
' Jessica Chen (jzc22)
' This program will calculate the BMI (Body Mass Index) given the inputed
' user weight and height.
' uses:
' lblWeight - Label - prompt for where user should enter weight, in kilograms
' lblHeight - Label - prompt for where user should enter height, in meters
' weightTB - TextBox - used to get user input for weight
' heightTB - TextBox - used to get user input for height
' calcBtn - Button - used by user to start task of calulating the BMI
' outputTB - TextBox - ReadOnly(True),Multiline(True),VerticalScroll - used to show user
' result of calculation and any warnings
Option Strict On
Option Explicit On
Option Infer Off
Option Compare Binary
Public Class bmiCalculator
Dim counter As Integer = 0
Private Sub calcBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcBtn.Click
counter += 1
Dim weight As Integer
weight = CInt(weightTB.Text)
Dim height As Integer
height = CInt(heightTB.Text)
Dim result As Double
If weight > 0 And height > 0 Then
result = (weight / height ^ 2)
outputTB.AppendText("Your BMI is " & CDbl(result) & "." & vbCrLf)
If result < 15.0 Then
outputTB.AppendText("Warning: Dangerous underweight condition!" & vbCrLf)
ElseIf result > 40.0 Then
outputTB.AppendText("Warning: Dangerous overweight condition!" & vbCrLf)
End If
If result >= 15.0 And result < 16.0 Then
outputTB.AppendText("Severely underweight" & vbCrLf)
End If
If result >= 16.0 And result < 18.5 Then
outputTB.AppendText("Underweight" & vbCrLf)
End If
If result >= 18.5 And result < 25.0 Then
outputTB.AppendText("Normal" & vbCrLf)
End If
If result >= 25.0 And result < 30.0 Then
outputTB.AppendText("Overweight" & vbCrLf)
End If
If result >= 30.0 And result < 35.0 Then
outputTB.AppendText("Moderately obese" & vbCrLf)
End If
If result >= 35.0 And result < 40.0 Then
outputTB.AppendText("Severely obese" & vbCrLf)
End If
outputTB.AppendText("Number of BMI Calculations: " & CStr(CDbl(counter)) & vbCrLf)
Else
If weight < 0 And height < 0 Then
outputTB.AppendText("Inputed height or weight not valid!" & vbCrLf)
End If
End If
End Sub
End Class
All I need help on is how to get the output text to replace the current text if I put in new values. In other words, if I put in 65 for weight and 1.2 for height and get a result, how do I get it to clear when I put in new values?