所以,我認爲我做錯了什麼,但需要一點指導。多個If語句縮進錯誤?
下面的代碼假設是基於組合框「頒獎」結果的一種計算方法。目前我的計算是錯誤地進行計算(因爲它認爲它是「兩個半數相同的期限」)。我相信這是由於我的縮進或不正確使用多個嵌套的if語句。
If Awarding = "First Half All Credits in One Half" Or Awarding = "Second Half Only" Then
If LEU.Value <> "" And PLEU < CalcElig Then
Payment1.Value = PLEU
If PAmtUnused < CalcElig Then
Payment1.Value = PAmtUnused
Else: Payment1.Value = Payment1.Value = Round(CLng(PSchAward) * PTotalAyWeeks/PMinAyWeeks/2, 0)
End If
PPayment1 = Payment1.Value
PPayment2 = 0
TotalPayment = PPayment1 + PPayment2
End If
End If
If Awarding = "Both Halfs Same Term" Then
If LEU.Value <> "" And PLEU < CalcEligA Then
Payment1.Value = PLEU
ElseIf PAmtUnused < CalcEligA Then
Payment1.Value = PAmtUnused
Else: Payment1.Value = CalcEligA
End If
PPayment1 = Payment1.Value
If LEU.Value <> "" And PLEU > 0 Then
Payment2.Value = PLEU - PPayment1
Else: Payment2.Value = CalcEligB
End If
If PAmtUnused - PPayment1 < PLEU - PPayment1 Then
Payment2.Value = PAmtUnused - PPayment1
ElseIf PAmtUnused - PPayment1 < CalcEligB Then
Payment2.Value = PAmtUnused - PPayment1
Else: Payment2.Value = CalcEligB
End If
PPayment2 = Payment2.Value
TotalPayment = PPayment1 + PPayment2
End If
End If
End Sub
壓痕不要緊,編譯器,它只是人類的利益。 –
好吧我出於某種原因認爲縮進至關重要?然後介意對我明顯的疏忽進行教育? –
如果你已經用Python編程,那麼你可能已經內化了縮進很重要的概念。原則上,在VBA中並不重要 - 儘管換行符形式的空白作爲語句終結者很重要。儘管如此,一致的縮進是一個非常好的主意,即使沒有人可以讀取代碼,因爲除此之外,它是調試中的一個主要幫助。 –