案例陈述不适合我

时间:2018-02-08 17:18:25

标签: excel vb.net switch-statement case

我无法理解下面的案例陈述出了什么问题......

Select Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count

    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count > 7
        protoWorksheet.Cells(rowCounter, 12) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 7
        protoWorksheet.Cells(rowCounter, 11) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 6
        protoWorksheet.Cells(rowCounter, 10) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 5 Or 4
        protoWorksheet.Cells(rowCounter, 9) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 3
        protoWorksheet.Cells(rowCounter, 8) = "X"
End Select

它唯一成功的案例是5 or 4,但只适用于4。我不知道我在哪里出错...提前谢谢。

1 个答案:

答案 0 :(得分:2)

从每个案例行中删除aFunction.getListOfWords.Intersect(aUTL.getListOfWords).CountSelect Case设置要测试的值,Case行只需要预期的输出。

使用OR时,只需列出以逗号分隔的值。

Select Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count

    Case  > 7
        protoWorksheet.Cells(rowCounter, 12) = "X"
    Case  7
        protoWorksheet.Cells(rowCounter, 11) = "X"
    Case  6
        protoWorksheet.Cells(rowCounter, 10) = "X"
    Case  5, 4
        protoWorksheet.Cells(rowCounter, 9) = "X"
    Case  3
        protoWorksheet.Cells(rowCounter, 8) = "X"
End Select