作者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