如果声明在vb.net中无法正常工作

时间:2015-05-05 00:41:23

标签: vb.net if-statement

我创建的If语句无法正常工作。它仅适用于每个条件的第一个子条件。所以说例如Combobox2.text被设置为" Running"和Combobox3.Text设置为值" 6mph" it won't return the value of CStr(472 / 80 * weight) in TextBox3.Text, but if Combobox2.text is set to "Running " and Combobox3.Text is set to "5mph" (the first condition after Combobox2.Text =" Running" )它将起作用,CStr(472 / 80 * weight)的值被分配给TextBox3.Text。有人可以帮助或者更好地告诉我是否有另一种方法来构建它以使其发挥作用。

If ComboBox2.Text = "Running" Then
        If ComboBox3.Text = "5mph" Then
            wez = CStr(472 / 80 * weight)
            TextBox3.Text = wez
        ElseIf ComboBox2.Text = "6mph" Then
            wez = CStr(590 / 80 * weight)
            TextBox3.Text = wez
        ElseIf ComboBox2.Text = "7mph" Then
            wez = CStr(679 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "8mph" Then
            wez = CStr(797 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "9mph" Then
            wez = CStr(885 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "10mph" Then
            wez = CStr(944 / 80 * weight)
            TextBox3.Text = wez
        End If

    ElseIf ComboBox2.Text = "Cycling" Then
        If ComboBox3.Text = "<10mph" Then

            wez = CStr(236 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "10 - 11.9mph" Then
            wez = CStr(354 / 80 * weight)
            TextBox3.Text = wez
        ElseIf ComboBox2.Text = "12 - 13.9mph" Then
            wez = CStr(472 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "16 - 20mph" Then
            wez = CStr(590 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "16 - 20mph" Then
            wez = CStr(708 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = ">20mph" Then
            wez = CStr(944 / 80 * weight)
            TextBox3.Text = wez
        End If

    ElseIf ComboBox2.Text = "Swimming" Then

        If ComboBox3.Text = "Freestyle, slow" Then

            wez = CStr(413 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "Freestyle, fast" Then
            wez = CStr(590 / 80 * weight)
            TextBox3.Text = wez
        ElseIf ComboBox2.Text = "Backstroke" Then
            wez = CStr(413 / 80 * weight)
            TextBox3.Text = wez

        ElseIf ComboBox2.Text = "Breaststroke" Then
            wez = CStr(590 / 80 * weight)
            TextBox3.Text = wez


        ElseIf ComboBox2.Text = "Butterfly" Then
            wez = CStr(649 / 80 * weight)
            TextBox3.Text = wez

        End If

    End If

1 个答案:

答案 0 :(得分:1)

因为,您在第二个ComboBox2.Text语句中再次检查If..Elseif...End If,但第一个If语句除外。

  

ElseIf ComboBox2.Text =“6mph”然后

试试这个

If ComboBox2.Text = "Running" Then
    If ComboBox3.Text = "5mph" Then
        wez = CStr(472 / 80 * weight)
        TextBox3.Text = wez
    ElseIf ComboBox3.Text = "6mph" Then
        wez = CStr(590 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "7mph" Then
        wez = CStr(679 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "8mph" Then
        wez = CStr(797 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "9mph" Then
        wez = CStr(885 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "10mph" Then
        wez = CStr(944 / 80 * weight)
        TextBox3.Text = wez
    End If

ElseIf ComboBox2.Text = "Cycling" Then
    If ComboBox3.Text = "<10mph" Then
        wez = CStr(236 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "10 - 11.9mph" Then
        wez = CStr(354 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "12 - 13.9mph" Then
        wez = CStr(472 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "16 - 20mph" Then
        wez = CStr(590 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "16 - 20mph" Then
        wez = CStr(708 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = ">20mph" Then
        wez = CStr(944 / 80 * weight)
        TextBox3.Text = wez

    End If

ElseIf ComboBox2.Text = "Swimming" Then

    If ComboBox3.Text = "Freestyle, slow" Then
        wez = CStr(413 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "Freestyle, fast" Then
        wez = CStr(590 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "Backstroke" Then
        wez = CStr(413 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "Breaststroke" Then
        wez = CStr(590 / 80 * weight)
        TextBox3.Text = wez

    ElseIf ComboBox3.Text = "Butterfly" Then
        wez = CStr(649 / 80 * weight)
        TextBox3.Text = wez

    End If
End If