你好,有人可以帮我在这里。我正在编写这个视觉基本功能,用于计算用户选定项目的价格。我已经使用了if if if循环,但只有第一部分显示输出,例如 我正在使用复选框进行选择,如果选中第一个复选框并单击了订单按钮,收据将填充价格和选定的项目,但这不会发生第二,第三...复选框。什么可能是错的?有人请帮助 下面是功能Visual basic If elseIf not working
Private Sub computeCurrentSelection()
If chkugalis.Checked = True Then 'ugali fish selected
orderAmt = lab.Text
total = ugalif * orderAmt
subtotal = total
lstReceipt.Items.Add(orderAmt & " plates of" & " Ugali n fish " & total & " Kshs")
ElseIf chkGitheri.Checked = True Then 'ugali dengu slected
orderAmt = lab3.Text
total = ugalid * orderAmt
lstReceipt.Items.Add(orderAmt & " plates of " & "Ugali n dengu " & total)
ElseIf chkUgaliB.Checked = True Then 'githeri selected
orderAmt = lab2.Text
total = githeri * orderAmt
lstReceipt.Items.Add(orderAmt & " plates of " & "Githeri " & total)
ElseIf chkPilau.Checked = True Then
orderAmt = lab4.Text
total = chapo * orderAmt
lstReceipt.Items.Add(orderAmt & " plates of " & "Pilau " & total)
ElseIf chkPizza.Checked = True Then
orderAmt = lab5.Text
total = pilau * orderAmt
lstReceipt.Items.Add(orderAmt & " plates of " & "Pizza " & total)
ElseIf chkMandazi.Checked = True Then
orderAmt = lab6.Text
total = pizza * orderAmt
lstReceipt.Items.Add(orderAmt & "mandazi " & total)
ElseIf chkSamosa.Checked = True Then
orderAmt = lab7.Text
total = mandazi * orderAmt
lstReceipt.Items.Add(orderAmt & "Samosa " & total)
ElseIf chkChapon.Checked = True Then
orderAmt = lab8.Text
total = samosa * orderAmt
lstReceipt.Items.Add(orderAmt & "Chapati " & total)
ElseIf chkWater.Checked = True And chk300ml.Checked = True Then
orderAmt = lab9.Text
total = water1 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 300ml" & "Water " & total)
ElseIf chkWater.Checked = True And chk500ml.Checked = True Then
orderAmt = lab9.Text
total = water2 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 500ml" & "Water " & total)
ElseIf chkWater.Checked = True And chk1l.Checked = True Then
orderAmt = lab9.Text
total = water3 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 1l" & "Water " & total)
ElseIf chkWater.Checked = True And chk2l.Checked = True Then
orderAmt = lab9.Text
total = water4 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 2l" & "Water " & total)
ElseIf chkSoda.Checked = True And chk300ml.Checked = True Then
orderAmt = lab10.Text
total = soda1 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 300ml" & "Soda " & total)
ElseIf chkSoda.Checked = True And chk500ml.Checked = True Then
orderAmt = lab10.Text
total = soda2 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 500ml" & "Soda " & total)
ElseIf chkSoda.Checked = True And chk1l.Checked = True Then
orderAmt = lab10.Text
total = soda3 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 1l" & "Soda " & total)
ElseIf chkSoda.Checked = True And chk2l.Checked = True Then
orderAmt = lab10.Text
total = soda4 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 2l" & "Soda " & total)
ElseIf chkJuice.Checked = True And chk300ml.Checked = True Then
orderAmt = lab11.Text
total = juice1 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 300ml" & "juice " & total)
ElseIf chkJuice.Checked = True And chk500ml.Checked = True Then
orderAmt = lab11.Text
total = juice2 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 500ml" & "juice " & total)
ElseIf chkJuice.Checked = True And chk1l.Checked = True Then
orderAmt = lab11.Text
total = juice3 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 1l" & "juice " & total)
ElseIf chkJuice.Checked = True And chk2l.Checked = True Then
orderAmt = lab11.Text
total = juice4 * orderAmt
lstReceipt.Items.Add(orderAmt & " Bottles of 2l" & "juice " & total)
End If
End Sub
其实这是我的第一个选择,但我避免了它,因为我需要检查是否有多个项目已被选中,它也没有工作。顺便说一下,你会介意告诉我,如果我的用法存在什么问题? –
但我发现他们为什么都没有工作。这实际上是你提到的另一种方式,谢谢 –