2016-11-17 53 views
-1

我正在爲我的類代碼和我在與功能部件的麻煩。Visual Basic函數優惠1和2

我目前有這個。我需要接受小計和使用計算折扣的函數小計> 200隨後的1%的折扣 小計> 100,然後.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

;隨行的任何功能有 – Plutonix

+0

我不知道到implemtn函數香港專業教育學院嘗試不同的東西,但它沒有工作 –

+0

這不是一個教程網站。 [函數聲明(Visual Basic)](https://msdn.microsoft.com/en-us/library/sect4ck6.aspx)做一些研究,然後張貼你嘗試過的東西並提出具體問題。 – Plutonix

回答

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) 
+0

我需要一個函數,將產生一個單獨的折扣價格從小計1%或.5_ –

+1

@ryandonald那是什麼功能 – Sid