Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

VB.net Price Calculation

I'm making an application to display the total price of a order. It decides the price based on the number of items ordered and if the customer is a wholesale or retailer.

Calculation it uses:

1-4 items = $10 per item if wholesaler.

5+ items = $9 each if wholesaler.

1-3 items = $15 per item if retailer.

4-8 item = $14 per item if retailer.

9+ item = $12 per item if retailer. I'm stuck on the calculation and confused as to how I would do it.

The GUI is complete, here is what I have so far:

Picture of GUI: http://i.imgur.com/P2tDz.png

Dim quantity As Decimal
Dim price As Decimal
Dim wholesaler As Integer
Dim retailer As Integer

Integer.TryParse(txtUnits.Text, price)

chkRetailer.Text = retailer
chkWholesale.Text = wholesaler


If wholesaler Then
    If Quantity <= 4 Then
        Price = 10
    Else
        Price = 9
    End If
ElseIf retailer Then
    If Quantity <= 3 Then
        Price = 15
    ElseIf Quantity <= 8 Then
        Price = 14
    Else
        Price = 12
    End If
End If

lblTotPrice.Text = price * quantity

lblTotPrice.Text = price.ToString("C0")

It's the calculation I'm confused on, I have the display and the declarations correct I believe.

Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This would be much clearer using Case statements (The VB example of the link provided is very helpful)

First use an IF statement to determine if you are a wholesaler and that determines which of the two case statements assigns the valid price


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...