【问题标题】:ElseIf Statement Not Reaching Msgbox ErrorElseIf 语句未到达 Msgbox 错误
【发布时间】:2015-01-07 12:25:36
【问题描述】:

输入错误数据时不会运行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

【问题讨论】:

    标签: vb.net if-statement msgbox


    【解决方案1】:

    你的错误在这里

    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

    【讨论】:

      【解决方案2】:

      请检查您的条件。 任何值都不能小于 10,也不能大于 600。 例如。让我们取重量= 3。 小于 10 但不大于 600。

      请更正您的条件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-10
        • 2020-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多