我正在为我的课程编写代码,而且我在使用功能部分时遇到了问题。
我目前有这个。我需要一个接受小计的函数,并使用小计>计算折扣。 200然后折扣1% 小计>然后折扣为0.5%
如果有人能指出正确的方向,我正在努力解决问题并需要帮助。谢谢。
Public Class Form1
Const constHandWashPrice As Decimal = 10D
Const constInteriorShampooPrice As Decimal = 30D
Const constCarWaxPrice As Decimal = 25D
Const constEngineShampooPrice As Decimal = 15D
Const constInteriorVacuumPrice As Decimal = 16D
Const constOilChangePrice As Decimal = 34.95D
Const constRustProofingPrice As Decimal = 89.99D
Const constTireRotationPrice As Decimal = 15D
Const constAlignmentPrice As Decimal = 63.88D
Const constFrontBrakesPrice As Decimal = 75.66D
Const constRearBrakesPrice As Decimal = 78.9D
Dim discount As Decimal
Dim total As Decimal
Dim subtotal As Decimal
Dim customername As Integer
Dim address As Integer
Private Sub cbservices_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbservices.SelectedIndexChanged
Dim index As Integer
Dim price As Decimal
Dim msg As String
index = cbservices.SelectedIndex
If index = 0 Then
price = constHandWashPrice
total += constHandWashPrice
subtotal += constHandWashPrice
End If
If index = 1 Then
price = constInteriorShampooPrice
total += constInteriorShampooPrice
subtotal += constInteriorShampooPrice
End If
If index = 2 Then
price = constCarWaxPrice
total += constCarWaxPrice
subtotal += constCarWaxPrice
End If
If index = 3 Then
price = constEngineShampooPrice
total += constEngineShampooPrice
subtotal += constEngineShampooPrice
End If
If index = 4 Then
price = constInteriorVacuumPrice
total += constInteriorVacuumPrice
subtotal += constInteriorVacuumPrice
End If
If index = 5 Then
price = constOilChangePrice
total += constOilChangePrice
subtotal += constOilChangePrice
End If
If index = 6 Then
price = constRustProofingPrice
total += constRustProofingPrice
subtotal += constRustProofingPrice
End If
If index = 7 Then
price = constTireRotationPrice
total += constTireRotationPrice
subtotal += constTireRotationPrice
End If
If index = 8 Then
price = constAlignmentPrice
total += constAlignmentPrice
subtotal += constAlignmentPrice
End If
If index = 9 Then
price = constFrontBrakesPrice
total += constFrontBrakesPrice
subtotal += constFrontBrakesPrice
End If
If index = 10 Then
price = constRearBrakesPrice
total += constRearBrakesPrice
subtotal += constRearBrakesPrice
End If
msg = cbservices.Items.Item(index) & vbTab & FormatCurrency(price)
lbss.Items.Add(msg)
lblsubtotal.Text = FormatCurrency(subtotal)
End Sub
Private Sub ClearToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClearToolStripMenuItem.Click
lbss.Items.Clear()
lbprint.Items.Clear()
lblsubtotal.Text = ""
txtad.Text = ""
txtcn.Text = ""
subtotal = 0
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
If MsgBox("Are you sure you want to exit?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
Application.Exit()
End If
End Sub
Private Sub PrintToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PrintToolStripMenuItem.Click
Dim index As Integer
lbprint.Items.Add("Sam's customer Care")
lbprint.Items.Add(Environment.NewLine)
lbprint.Items.Add("Bill to:" & txtcn.Text.ToString & vbTab & txtad.Text.ToString)
lbprint.Items.Add(Environment.NewLine)
Do While index < lbss.Items.Count
lbprint.Items.Add(lbss.Items(index))
index += 1
Loop
lbprint.Items.Add("--------------------------------------------------------------------------")
lbprint.Items.Add("Subtotal: " & FormatCurrency(subtotal))
lbprint.Items.Add("Discount: " & FormatCurrency(discount))
End Sub
答案 0 :(得分:0)
您是否正在寻找给予总折扣的功能?像这样?
Private Function GetDiscountedTotal(subtotal As Decimal) As Decimal
Return If(subtotal > 100, If(subtotal > 200, subtotal - (subtotal * 0.1D), subtotal - (subtotal * 0.5D)), subtotal)
End Function
使用示例
subtotal = GetDiscountedTotal(subtotal)