2

只是好奇,但有什么办法可以减少代码行数?

For k = 1 To 12
    Select Case k
        Case 1
            col = 9
        Case 2
            col = 10
        Case 3
            col = 11
        Case 4
            col = 12
        Case 5
            col = 13
        Case 6
            col = 14
        Case 7
            col = 15
        Case 8
            col = 16
        Case 9
            col = 17
        Case 10
            col = 18
        Case 11
            col = 19
        Case 12
            col = 20
    End Select
Next

谢谢!

4

1 回答 1

2

怎么样:

For k = 1 to 12
   col = k + 8
Next

或者您可能正在寻找的内容:

For k = 1 To 12
    Select Case k
        Case 1 To 12
            col = k + 8
    End Select
Next

这是相关的 MSDN,您可以向下滚动查看示例。

于 2012-10-26T00:46:02.457 回答