作者teybend (圈圈)
看板Visual_Basic
標題[.NET] 新手請教 if條件先後順序差別
時間Sun Nov 28 00:15:13 2010
"前面敘述可以不看 直接看最後 "
簡述:我在設定一個簡單的點餐系統
在三個群主方塊裡 設要不要點餐的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
1F:→ teybend:另外..文字方塊能不能規定一定要填入? 11/28 12:05
2F:推 LPH66:請搞懂 += 做了什麼事 11/28 18:40
3F:推 followmeyo:我覺得你對於IF觀念有點錯誤 12/02 21:01
4F:→ phida:amountTotal 沒有初始值Dim amountTotal as integer = 0 12/09 00:48