我正在编写一个非常简单的体重计算器代码--用户输入体重和身高,我计算该身高的标准体重,然后该代码将该体重与if/elseif if块中基于标准的体重范围进行比较。
标准体重返回正确,但代码始终返回"Normal Weight",而不考虑身高与体重的比例。我是VB的新手,所以我的直觉是它是一个相对简单的语法问题。
Dim dbHeight, dbWeight, dbStWeight As Double
dbHeight = CDbl(tbxHeight.Text)
dbWeight = CDbl(tbxWeight.Text)
dbStWeight = (dbHeight * 30.48 - 105) / 0.454
lblFeedback.Text = ("Your standard weight is " & dbStWeight)
If (dbStWeight * 0.9 <= dbWeight <= dbStWeight * 1.1) Then
lblResult.Text = ("Normal Weight")
ElseIf (dbStWeight * 1.1 < dbWeight <= dbStWeight * 1.2) Then
lblResult.Text = ("Over Weight")
ElseIf (dbStWeight * 0.8 <= dbWeight < dbStWeight * 0.9) Then
lblResult.Text = ("Under Weight")
ElseIf (dbWeight > dbStWeight * 1.2) Then
lblResult.Text = ("Very overweight")
ElseIf (dbWeight < dbStWeight * 0.8) Then
lblResult.Text = ("Very underweight")
End If
lblFeedback.Refresh()
lblResult.Refresh()发布于 2015-11-06 02:08:36
Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
Dim dbHeight, dbWeight, dbStWeight As Double
dbHeight = CDbl(tbxHeight.Text)
dbWeight = CDbl(tbxWeight.Text)
dbStWeight = (dbHeight * 30.48 - 105) / 0.454
StWeight.Text = ("Your standard weight is " & dbStWeight)
If (dbStWeight * 0.9 <= dbWeight) AndAlso (dbWeight <= dbStWeight * 1.1) Then
Result.Text = ("Normal Weight")
ElseIf (dbStWeight * 1.1 <= dbWeight) AndAlso (dbWeight <= dbStWeight * 1.2) Then
Result.Text = ("Overweight")
ElseIf (dbStWeight <= dbWeight) AndAlso (dbWeight < dbStWeight * 0.9) Then
Result.Text = ("Underweight")
ElseIf (dbWeight > dbStWeight * 1.2) Then
Result.Text = ("Very overweight")
ElseIf (dbWeight < dbStWeight * 0.8) Then
Result.Text = ("Very underweight")
End If
End Subhttps://stackoverflow.com/questions/33550786
复制相似问题