我正在尝试在 Visual Basic 中编写一个简单的程序,它通过一个类传递一个变量,计算它,然后返回它。我的表格“Pizza”有 2 组,每组有 3 个单选按钮。单击总计按钮时,比萨大小价格将添加到比萨饼皮价格中。我通过故障排除发现它只添加了“createPizza.Crust”+“createPizza.Size”。我错过了什么。感谢您的任何帮助。
Form "Pizza"
Public Class Pizza
Private Sub btnTotal_Click(sender As Object, e As EventArgs) Handles btnTotal.Click
If rThin.Checked = True Then
createPizza.Crust = 1
ElseIf rPan.Checked = True Then
createPizza.Crust = 2
ElseIf rStuff.Checked = True Then
createPizza.Crust = 3
End If
If rSm.Checked = True Then
createPizza.Size = 1
ElseIf rMm.Checked = True Then
createPizza.Size = 2
ElseIf rLg.Checked = True Then
createPizza.Size = 3
End If
lblTotal.Text = "Total: " + createPizza.PizTotal.ToString()
End Sub
End Class
“创建披萨”类
Public Class createPizza
Public Shared Size As Double
Public Shared Crust As Double
Public Shared Property pizzaCrust As Double
Get
Return Crust
End Get
Set(ByVal crustpr As Double)
If Crust = 1 Then
crustpr = 1
ElseIf Crust = 2 Then
crustpr = 1.5
ElseIf Crust = 3 Then
crustpr = 3
End If
Crust = crustpr
End Set
End Property
Public Shared Property pizzaSize As Double
Get
Return Size
End Get
Set(ByVal sizepr As Double)
If Size = 1 Then
sizepr = 10.0
ElseIf Size = 2 Then
sizepr = 12.5
ElseIf Size = 3 Then
sizepr = 15
End If
Size = sizepr
End Set
End Property
Public Shared Function PizTotal() As Decimal
Return pizzaCrust + pizzaSize
End Function
End Class