Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB. Help with percentage.
#1
Basically, this is what I am supposed to do:

Quote:Write an application that accepts from the user the wholesale cost of an item and its markup percentage. (For example, if an item's wholesale cost is $5 and its retail price is $10, the the markup is 100%.

When the user clicks the Get Retail button, the program should do the following:
-Verify that the values entered by the user for the wholesale cost and the markup % are numeric and not negative [I'm assuming I'm going to Dim my two textboxes + label as Decimal.]
-Call the CalcRetail button
-Display the retail cost as returned from the function

What I have so far (and I think I'm doing this wrong, I just hit a dead-end at the percentage):

[Image: osupvb.png]
[Image: osupvb2.png]


The set that grey'd out area as lblRetail, because in the book, the Retail Price number is the answer.
Reply
#2
A simple way to handle this is:
Code:
Private Sub CalcRetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcRetail.Click Dim curWholesale, curRetail as Currency, decMarkup As Decimal

curWholesale = txtWholesale.Text
decMarkup = txtMarkup.text / 100
If decMarkup < 0 Then
MsgBox("Markup percentage cannot  be lower than 0%.")
End If
curRetail = curWholeSale * decMarkup
lblRetail.Text = curRetail
End Sub

Excuse me if my coding is dirty, I haven't touched this in two years. Also, if you want to allow negative markups, you may want to remove that MsgBox line but do something else to prevent negative curRetail, like:
Code:
If curRetail < 0 Then
curRetail = 0
End If
Reply
#3
Infection Wrote:A simple way to handle this is:
Code:
Private Sub CalcRetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcRetail.Click Dim curWholesale, curRetail as Currency, decMarkup As Decimal

curWholesale = txtWholesale.Text
decMarkup = txtMarkup.text / 100
If decMarkup < 0 Then
MsgBox("Markup percentage cannot  be lower than 0%.")
End If
curRetail = curWholeSale * decMarkup
lblRetail.Text = curRetail
End Sub

Excuse me if my coding is dirty, I haven't touched this in two years. Also, if you want to allow negative markups, you may want to remove that MsgBox line but do something else to prevent negative curRetail, like:
Code:
If curRetail < 0 Then
curRetail = 0
End If

No problem. Thanks for the help, actually. Going to try that, actually. I never thought of even using "If" statements. :|
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)