2013-02-24 69 views
0

我遇到了一个使用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 

感谢您的任何帮助。

+0

我不认为你可以使用“AND”在你的IF块中的一行中做两个分配。 – Jesse 2013-02-24 01:39:41

+0

我认为你是对的。我刚刚删除了一半,它只用于底层。猜猜我将不得不为地毯侧添加另一个IF块。 – 2013-02-24 01:43:12

+1

你不需要另一个if块,只需取出AND并将第二个赋值放在一个新行上。 – Jesse 2013-02-24 01:44:39

回答

2

您不能使用AND将两个不同的分配串起来。你的IF块应该是

If EconomyRadioButton.Checked Then 
    UnderlayPrice = 3.95 
    CarpetPrice = 12.95 
ElseIf DeluxeRadioButton.Checked Then 
    UnderlayPrice = 4.95 
    CarpetPrice = 15.49 
ElseIf PlushRadioButton.Checked Then 
    UnderlayPrice = 5.95 
    CarpetPrice = 19.95 
End If 
+0

太棒了!很高兴你帮他解决了 – Jeremy 2013-02-24 06:03:36

+0

谢谢@JeremyChild,有时候是让我们绊倒的小事,只需要新鲜的眼睛。 – Jesse 2013-02-24 06:05:31

+0

谢谢!标记为正确的答案 – 2013-02-24 15:37:02

-1

使用变量和if语句不使用AND运算... ADN运营商使用IF条件如果< 20和> 10,然后..try尝试UNT