2016-11-17 1 views
-1

Ich arbeite an einem Code für meine Klasse und ich habe Probleme mit der Funktion Teil.Visual Basic Funktion Rabatte 1 und 2

Ich habe derzeit dies. Ich brauche eine Funktion, die die Zwischensumme akzeptiert und berechnet den Rabatt mit Zwischensumme> 200 dann einen Rabatt von 1% Zwischensumme> 100 dann einen Rabatt von 0,5%

Ich habe Probleme mit Funktionen und brauche Hilfe, wenn jemand mich zeigen könnte in die richtige Richtung bitte und danke.

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

Arent gibt keine Funktionen gibt – Plutonix

+0

Ich bin mir nicht sicher, dass die Funktion ive verschiedene Dinge versucht implemtn aber es hat nicht –

+0

arbeiten Dies ist kein Tutorial-Website. [Funktionsstatement (Visual Basic)] (https://msdn.microsoft.com/en-us/library/sect4ck6.aspx) Recherchieren Sie dann, was Sie versucht haben und stellen Sie eine bestimmte Frage. – Plutonix

Antwort

0

Suchen Sie eine Funktion, die insgesamt gegeben einen Rabatt macht? So was?

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 

Anwendungsbeispiel

subtotal = GetDiscountedTotal(subtotal) 
+0

Ich brauche eine Funktion, die einen separaten Rabattpreis von der Zwischensumme entweder 1% oder .5_ –

+1

@ryandonald das ist, was diese Funktion tut – Sid