选择案例编号范围未注册

时间:2016-10-04 12:41:42

标签: vba excel-vba switch-statement excel

我在下面有一个简单的case语句,它应该在Case -1 To -10的情况下评估-1并且它正在跳过它。我最初认为这个错误来自于Select Case Val(firstOptionLegArray(UBound(firstOptionLegArray))) + Val(secondOptionLegArray(UBound(secondOptionLegArray))),因为它并没有根据我的预期进行评估(在这个特定情况下它应该是+1 + -2)。

抛出Debug.Print行,实际上正如预期的那样评估为-1。我错过了什么?

Debug.Print Val(firstOptionLegArray(UBound(firstOptionLegArray))) + Val(secondOptionLegArray(UBound(secondOptionLegArray)))

                Select Case Val(firstOptionLegArray(UBound(firstOptionLegArray))) + Val(secondOptionLegArray(UBound(secondOptionLegArray)))

                    Case 0
                    'No ratio

                        assemblyString = "LIVE " & GetOptionCodes(Mid(tradeLegStructureArray(0), 8, 2)) & " " & TranslateExpirationDate(firstOptionLegArray(3)) & " " & Format(firstOptionLegArray(5), "##0.00") & "/" & _
                        Format(secondOptionLegArray(5), "##0.00") & " Fence"

                    Case -1 To -10
                    'Ratio

                        assemblyString = "LIVE " & GetOptionCodes(Mid(tradeLegStructureArray(0), 8, 2)) & " " & TranslateExpirationDate(firstOptionLegArray(3)) & " " & Format(firstOptionLegArray(5), "##0.00") & "/" & _
                        Format(secondOptionLegArray(5), "##0.00") & " " & Abs(firstOptionLegArray(UBound(firstOptionLegArray))) & "x" & Abs(secondOptionLegArray(UBound(secondOptionLegArray))) & " Fence"

                End Select

1 个答案:

答案 0 :(得分:3)

line

中的值必须按升序排列
Case -10 To -1