Luis
Luis

Reputation: 139

Select case based upon form option button

I have a form set up with couple parameters. I have set up my form with two option button "Rolling" and "One Time". I would like to set this up as a condition to select which case to use. For Example if "One time" is selected use select case WITHOUT extend ELSE use select case WITH EXTEND. The below code is what I have now not sure if I am doing this condition correctly.

If OnetimeOption.value = True Then

    Select Case MonthComboBox.value
        Case "Week One"
            iCol = "BB"

        Case "Week Two"
            iCol = "BC"

        Case "Week Three"
            iCol = "BD"

        Case "Week Four"
            iCol = "BE"

        Case "Week Five"
            iCol = "BF"

        Case "Week Six"
            iCol = "BG"

        Case "One Seven"
            iCol = "BH"

        Case "One Eight"
            iCol = "BI"

        Case "One Nine"
            iCol = "BJ"

        Case "One Ten"
            iCol = "BK"

        Case "One Eleven"
            iCol = "BL"

        Case "One Twelve"
            iCol = "BM"
    End Select

Else



    nExtend = 1 'Set this as a default.
    Select Case MonthComboBox.value

        Case "Week One"
            iCol = "BB"
            nExtend = 12
        Case "Week Two"
            iCol = "BC"
            nExtend = 11
        Case "Week Three"
            iCol = "BD"
            nExtend = 10
        Case "Week Four"
            iCol = "BE"
            nExtend = 9
        Case "Week Five"
            iCol = "BF"
            nExtend = 8
        Case "Week Six"
            iCol = "BG"
            nExtend = 7
        Case "One Seven"
            iCol = "BH"
            nExtend = 6
        Case "One Eight"
            iCol = "BI"
            nExtend = 5
        Case "One Nine"
            iCol = "BJ"
            nExtend = 4
        Case "One Ten"
            iCol = "BK"
            nExtend = 3
        Case "One Eleven"
            iCol = "BL"
            nExtend = 2
        Case "One Twelve"
            iCol = "BM"
            nExtend = 1
    End Select

End If

Upvotes: 0

Views: 2114

Answers (1)

user6432984
user6432984

Reputation:

I would write it differently if both Select Cases used the same set of values. But they don't. I would, however, combine cases that have the same result.

If OnetimeOption.Value = True Then

    Select Case MonthComboBox.Value
        Case "Week One"
            iCol = "C"
        Case "Week Two"
            iCol = "N"
        Case "Week Three"
            iCol = "O"
        Case "Week 4"
            iCol = "P"
        Case "Week 5", "Week 6", "One Month"
            iCol = "Q"
    End Select

Else
    nExtend = 1   'Set this as a default.
    Select Case MonthComboBox.Value
        Case "Week One"
            iCol = "C"
        Case "Week One"
            iCol = "N"
            nExtend = 4
        Case "Current Month +2"
            iCol = "O"
            nExtend = 3
        Case "Current Month +3"
            iCol = "P"
            nExtend = 2
        Case "Current Month +4"
            iCol = "Q"
    End Select

End If

Upvotes: 1

Related Questions