我正在爲我的學校課程構建一個計算項目,並且我有一個相當大的if
聲明。當我運行這個程序時,它一點都不慢,但是我只是想知道寫大的if
語句是否被認爲是不好的。Long if statement
For BookingNumber = 0 To intBookingCount - 1
If intStartPeriod(BookingNumber) = 1 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton1.Enabled = False
If intLength(BookingNumber) = 1 Then
ElseIf intLength(BookingNumber) = 2 Then
radRadioButton2.Enabled = False
ElseIf intLength(BookingNumber) = 3 Then
radRadioButton2.Enabled = False
radRadioButton3.Enabled = False
ElseIf intLength(BookingNumber) = 4 Then
radRadioButton2.Enabled = False
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
ElseIf intLength(BookingNumber) = 5 Then
radRadioButton2.Enabled = False
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
ElseIf intLength(BookingNumber) = 6 Then
radRadioButton2.Enabled = False
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
ElseIf intLength(BookingNumber) = 7 Then
radRadioButton2.Enabled = False
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
radRadioButton7.Enabled = False
End If
ElseIf intStartPeriod(BookingNumber) = 2 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton2.Enabled = False
If intLength(BookingNumber) = 2 Then
radRadioButton3.Enabled = False
ElseIf intLength(BookingNumber) = 3 Then
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
ElseIf intLength(BookingNumber) = 4 Then
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
ElseIf intLength(BookingNumber) = 5 Then
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
ElseIf intLength(BookingNumber) = 6 Then
radRadioButton3.Enabled = False
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
radRadioButton7.Enabled = False
End If
ElseIf intStartPeriod(BookingNumber) = 3 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton3.Enabled = False
If intLength(BookingNumber) = 2 Then
radRadioButton4.Enabled = False
ElseIf intLength(BookingNumber) = 3 Then
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
ElseIf intLength(BookingNumber) = 4 Then
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
ElseIf intLength(BookingNumber) = 5 Then
radRadioButton4.Enabled = False
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
radRadioButton7.Enabled = False
End If
ElseIf intStartPeriod(BookingNumber) = 4 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton4.Enabled = False
If intLength(BookingNumber) = 2 Then
radRadioButton5.Enabled = False
ElseIf intLength(BookingNumber) = 3 Then
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
ElseIf intLength(BookingNumber) = 4 Then
radRadioButton5.Enabled = False
radRadioButton6.Enabled = False
radRadioButton7.Enabled = False
End If
ElseIf intStartPeriod(BookingNumber) = 5 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton5.Enabled = False
If intLength(BookingNumber) = 2 Then
radRadioButton6.Enabled = False
ElseIf intLength(BookingNumber) = 3 Then
radRadioButton6.Enabled = False
radRadioButton7.Enabled = False
End If
ElseIf intStartPeriod(BookingNumber) = 6 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton6.Enabled = False
If intLength(BookingNumber) = 2 Then
radRadioButton7.Enabled = False
End If
ElseIf intStartPeriod(BookingNumber) = 7 And strComputerRoom(BookingNumber) = strCR Then
radRadioButton7.Enabled = False
End If
Next
Next
End Function
向我們展示 - 如果我們看不到代碼,我們不知道您的意思。 – Oded 2013-03-20 19:54:29
是的,我用來創建long if語句,但是我發現它們很難調試,如果語句有問題,您不知道問題出在哪裏,那麼if語句很大就是不好的形式 – 2013-03-20 19:58:34
取決於它的易理解性是。不喜歡他們自己太容易迷路。 – 2013-03-20 20:04:04