当前位置:编程学习 > C#/ASP.NET >>

B.M.I指数计算器出现了输出时候的小问题,求解!


Public Class Form1 
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click 
'Note: the program is built to evaluate people's health rate via calculating B.M.I.(Body Mass Index). 
'The user interface consists of the weight and height input module and the output display panel. 
'The users will just have to input their weight and height value to get their health evaluation. 
If IsNumeric(TB1.Text) = False Then 
TB3.Text = "Invalid input value" 
Exit Sub 
End If 
If IsNumeric(TB2.Text) = False Then 
TB3.Text = "Invalid input value" 
Exit Sub 
End If 
Dim w As Double = TB1.Text 
Dim h As Double = TB2.Text 
Dim bmi As Double = w * 703 \ (h ^ 2)

If bmi < 15 Then 
TB3.Text = bmi & vbCrLf & "Very severely underweight" & MessageBox.Show("You are in a dangerous UNDERWEIGHT condition! Save yourself!") 
End If

If bmi >= 15 And bmi < 16 Then 
TB3.Text = bmi & vbCrLf & "Severely underweight" 
End If

If bmi >= 16 And bmi < 18.5 Then 
TB3.Text = bmi & vbCrLf & "Underweight" 
End If

If bmi >= 18.5 And bmi <= 25 Then 
TB3.Text = bmi & vbCrLf & "Normal" 
End If

If bmi >= 25 And bmi < 30 Then 
TB3.Text = bmi & vbCrLf & "Overweight" 
End If

If bmi >= 30 And bmi < 35 Then 
TB3.Text = bmi & vbCrLf & "Moderately obese" 
End If

If bmi >= 35 And bmi < 40 Then 
TB3.Text = bmi & vbCrLf & "Severely obese" 
End If

If bmi >= 40 Then 
TB3.Text = bmi & vbCrLf & "Very severely obese" & MessageBox.Show("You are in a dangerous OVERWEIGHT condition! Save yourself!") 
End If 
End Sub
End Class
   
    debug的时候如果输出的bmi达到了最小或者最大的两种情况(也就是要弹出messagebox的两种情况),那TB3.TEXT就会出现在应该输出的问题后面带一个数字1的情况,如图
--------------------编程问答-------------------- --------------------编程问答-------------------- If bmi < 15 Then
TB3.Text = bmi + Constants.vbCrLf + "Very severely underweight"
MessageBox.Show("You are in a dangerous UNDERWEIGHT condition! Save yourself!")
End If
--------------------编程问答-------------------- 懒得看这个程序了。我希望这个作者首先学会写 Else If。
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,