[.NET] 新手請教 if條件先後順序差別
"前面敘述可以不看 直接看最後 "
簡述:我在設定一個簡單的點餐系統
在三個群主方塊裡 設要不要點餐的checkbox
以及 選擇餐點radioButton
我想操作即使點了radioButton 但是沒點checkbox一樣不會顯示金額
原始碼 :Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim total As Integer = 0
Dim total1 As Integer
Dim total2 As Integer
Dim amountTotal As Integer
If chkChicken.Checked Then
total += 120
End If
If chkFries.Checked Then
total1 = IIf(rdbSmall.Checked, 25, 40)
End If
If rdbCola.Checked Then
total2 = 30
End If
If rdbMilk.Checked Then
total2 = 30
End If
*** 下面是重點 ***
amountTotal = total + total1
(假如上面這句跟下面交換順序 結果就會失敗)
(請問邏輯上是錯在哪裡 )
If chkDrink.Checked Then
amountTotal += total2
End If
lblOutput.Text = Format(amountTotal, "C")
End Sub
End class
請幫我找出他的邏輯錯在哪?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.171.208.146
→
11/28 12:05, , 1F
11/28 12:05, 1F
推
11/28 18:40, , 2F
11/28 18:40, 2F
推
12/02 21:01, , 3F
12/02 21:01, 3F
→
12/09 00:48, , 4F
12/09 00:48, 4F