Alex Dada
Alex Dada

Reputation: 63

If statement not working properly in vb.net

The If statement i created doesn't work properly. It only works for the first sub condition of every condition. So say for example Combobox2.text is set to "Running " and Combobox3.Text is set to the value "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 afterCombobox2.Text = "Running" ) it will work and the value of CStr(472 / 80 * weight) is assigned to TextBox3.Text. Can someone please help or better still tell me if there's another way of structuring this in order for it to work.

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

Upvotes: -1

Views: 1947

Answers (1)

Saagar Elias Jacky
Saagar Elias Jacky

Reputation: 2688

Because, you are checking for ComboBox2.Text again - inside the second If..Elseif...End If statements, except for the first If statement.

ElseIf ComboBox2.Text = "6mph" Then

Try this

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

Upvotes: 1

Related Questions