[.NET] 新手請教 if條件先後順序差別

看板Visual_Basic作者 (圈圈)時間15年前 (2010/11/28 00:15), 編輯推噓2(202)
留言4則, 4人參與, 最新討論串1/1
"前面敘述可以不看 直接看最後 " 簡述:我在設定一個簡單的點餐系統 在三個群主方塊裡 設要不要點餐的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
我覺得你對於IF觀念有點錯誤
12/02 21:01, 3F

12/09 00:48, , 4F
amountTotal 沒有初始值Dim amountTotal as integer = 0
12/09 00:48, 4F
文章代碼(AID): #1CyIwKmo (Visual_Basic)