ElseIf 语句未到达 Msgbox 错误
ElseIf Statement Not Reaching Msgbox Error
输入不正确的数据时不会运行错误消息框
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
你的错误在这里
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
请检查您的条件。
任何值都不能小于 10 也不能大于 600。
例如。让我们称重 = 3。
小于10但不大于600.
请更正您的条件。
输入不正确的数据时不会运行错误消息框
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
你的错误在这里
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
请检查您的条件。 任何值都不能小于 10 也不能大于 600。 例如。让我们称重 = 3。 小于10但不大于600.
请更正您的条件。