我遇到了一个使用VB 2010的问题 - 我试图根据3个单选按钮中的1选择计算地毯的成本。VB 2010表单上的单选按钮成本计算
我有这个在我的表单顶部:
Private CarpetPrice, UnderlayPrice As Decimal
这里是我的按钮的代码单击
Private Sub CostButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CostButton.Click
' Calculate button click
' Radio Button IF Statement for calculating cost
If EconomyRadioButton.Checked Then
UnderlayPrice = 3.95 And CarpetPrice = 12.95
ElseIf DeluxeRadioButton.Checked Then
UnderlayPrice = 4.95 And CarpetPrice = 15.49
ElseIf PlushRadioButton.Checked Then
UnderlayPrice = 5.95 And CarpetPrice = 19.95
End If
' Start Calculations
CarpetNumLabel.Text = (((Length1TextBox.Text * Width1TextBox.Text)/1296) + ((Length2TextBox.Text * Width2TextBox.Text)/1296) + _
((Length3TextBox.Text * Width3TextBox.Text)/1296) + ((HallLengthTextBox.Text * HallWidthTextBox.Text)/1296)) * 1.05
UnderlayNumLabel.Text = CarpetNumLabel.Text
TackNumLabel.Text = ((Length1TextBox.Text/96) + (Width1TextBox.Text/96) + (Length2TextBox.Text/96) + (Width2TextBox.Text/96) _
+ (Length3TextBox.Text/96) + (Width3TextBox.Text/96) + (HallLengthTextBox.Text/96) + (HallWidthTextBox.Text/96)) * 1.1
ScrewNumLabel.Text = ((TackNumLabel.Text/1.1) * 8)/50
CarpetCostLabel.Text = CarpetNumLabel.Text * CarpetPrice
UnderlayCostLabel.Text = UnderlayNumLabel.Text * UnderlayPrice
TackCostLabel.Text = TackNumLabel.Text
ScrewCostLabel.Text = ScrewNumLabel.Text * 2.85
End Sub
眼下一切都只是在地毯上运行完美,垫层不计算价格。当我点击按钮时,我还需要做其他事情才能让程序识别单选按钮的状态吗? -
我想我的问题出在:
CarpetCostLabel.Text = CarpetNumLabel.Text * CarpetPrice
UnderlayCostLabel.Text = UnderlayNumLabel.Text * UnderlayPrice
感谢您的任何帮助。
我不认为你可以使用“AND”在你的IF块中的一行中做两个分配。 – Jesse 2013-02-24 01:39:41
我认为你是对的。我刚刚删除了一半,它只用于底层。猜猜我将不得不为地毯侧添加另一个IF块。 – 2013-02-24 01:43:12
你不需要另一个if块,只需取出AND并将第二个赋值放在一个新行上。 – Jesse 2013-02-24 01:44:39