2015-01-07 26 views
-2

当进入elseif的语句时,没有到达MSGBOX错误

不正确的数据将无法运行的错误MSGBOX
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     Dim weight As Decimal 
     Dim height As Decimal 
     Dim bmi As Decimal 
     weight = InputBox("enter weight") 
     height = InputBox("enter height") 
     If weight > 10 And weight <= 600 And height >= 0.5 And height <= 2.7 Then 
      bmi = weight/(height)^2 
     ElseIf weight <= 10 And weight > 600 Then 
      MsgBox("you have enterd in valid data it must be above 10 and below or equal 600") 
     ElseIf height < 0.5 And height > 2.7 Then 
      MsgBox("you have enterd in valid data it must between 0.5 and 2.7 inclusive") 
     End If 
     TextBox1.Text = bmi 
End Sub 

回答

2

你的错误是在这里

ElseIf weight <= 10 And weight > 600 Then 
     MsgBox("you have enterd in valid data it must be above 10 and below or equal 600") 
    ElseIf height < 0.5 And height > 2.7 Then 
     MsgBox("you have enterd in valid data it must between 0.5 and 2.7 inclusive") 
    End If 

你的体重是永远不会小于或等于10并且大于600。身高同样适用

您需要使用OR来代替AND

+0

欢呼声并没有意识到我曾经使用“和”而不是“或” –

0

请检查您的条件。 没有任何值可以小于10,也可以大于600. 例如。让我们取weigth = 3. 它小于10但不大于600.

请更正您的条件。