1

有没有办法让这更有效?我觉得有点丑。我想验证是否有下一个“甲板”,如果有,执行一些,直到甲板8

这是我的代码:

         If deckNum > 0 Then
            'Execute code for deck 1
            If deckNum > 1 Then
                'Execute code for deck 2
                If deckNum > 2 Then
                    'Execute code for deck 3
                    If deckNum > 3 Then
                        'Execute code for deck 4
                        If deckNum > 4 Then
                            'Execute code for deck 5
                            If deckNum > 5 Then
                                'Execute code for deck 6
                                If deckNum > 6 Then
                                    'Execute code for deck 7
                                    If deckNum > 7 Then
                                        'Execute code for deck 8
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
         End If
4

2 回答 2

3

使用案例陈述

Select Case deckNum

case 0
    'execute code for deck 0
case 1
    'execute code for deck 1
case 2
    'execute code for deck 2
case 3
    'execute code for deck 3 
End Select

这是一个办公室 VBA 参考http://msdn.microsoft.com/en-us/library/office/gg278454.aspx

于 2013-10-18T17:23:19.543 回答
0

根据我的评论,如果您Execute code for..是单班轮,请参阅option 1其他内容option 2

第二件事,您必须反向检查任何大于0将触发Deck 1代码的数字。

选项1

替换MsgBox...为您的一个班轮代码。

Select Case deckNum
    Case Is > 7: MsgBox "A"
    Case Is > 6: MsgBox "B"
    Case Is > 5: MsgBox "C"
    Case Is > 4: MsgBox "D"
    Case Is > 3: MsgBox "E"
    Case Is > 2: MsgBox "F"
    Case Is > 1: MsgBox "G"
    Case Is > 0: MsgBox "H"
End Select

选项 2

Select Case deckNum
    Case Is > 7: proc1
    Case Is > 6: proc2
    Case Is > 5: Proc3
    Case Is > 4: Proc4
    Case Is > 3: Proc5
    Case Is > 2: Proc6
    Case Is > 1: Proc7
    Case Is > 0: Proc8
End Select

Sub proc1()

End Sub

Sub proc2()

End Sub

'
'~~> And So oN
'
于 2013-10-18T17:28:28.580 回答