0

I am working out a problem for my programming class and was wondering if I could get some help. The code below is supposed to get a discount for specific model numbers (AX1 and SD2) at 10% off. All other inputs are to be discounted at 5%. What happens now with the code is just a flat message box with the original entered price.

Private Sub DiscountCalc_Click()

Dim strModelNum As String
Dim curOrigPrice As Currency
Dim sngRate As Long
Dim curDiscount As Long
Dim curNewPrice As Currency


strModelNum = InputBox("Enter desired model number", "Price Lookup")
strModelNum = UCase(strModelNum)

curOrigPrice = InputBox("Enter the original Price", "Price Lookup")
sngRate = 0.1
curDiscount = 0.05


If strModelNum = "AX1" Then
  curNewPrice = curOrigPrice - (curOrigPrice * sngRate)
Else If strModelNum = "SD2" Then
  curNewPrice = curOrigPrice - (curOrigPrice * sngRate)
Else
    curNewPrice = curOrigPrice - (curOrigPrice * curDiscount)
End If

   MsgBox curNewPrice

End Sub
2
  • It seems that you have an excess on one End If. Is this intentional or what? I have edited some lines for you.Thanks! Commented Mar 1, 2016 at 8:59
  • The extra endif was a result of being inexperienced. Thank you! Commented Mar 1, 2016 at 17:55

3 Answers 3

1

Try:

If strModelNum = "AX1" Or strModelNum = "SD2" Then
    curNewPrice = curOrigPrice - (curOrigPrice * sngRate)
Else
    curNewPrice = curOrigPrice - (curOrigPrice * curDiscount)
End If
Sign up to request clarification or add additional context in comments.

2 Comments

Also need to change the two longs to doubles. The long is rounding it to 0
Good catch - missed that
1

Try this code.

You will need to change Long to Double. Also you can compact your IF statements a little.

Private Sub DiscountCalc_Click()

Dim strModelNum As String
Dim curOrigPrice As Double
Dim sngRate As Double
Dim curDiscount As Double
Dim curNewPrice As Double


strModelNum = InputBox("Enter desired model number", "Price Lookup")
strModelNum = UCase(strModelNum)

curOrigPrice = InputBox("Enter the original Price", "Price Lookup")
sngRate = 0.1
curDiscount = 0.05


If strModelNum = "AX1" Or strModelNum = "SD2" Then
  curNewPrice = curOrigPrice - (curOrigPrice * sngRate)
Else
    curNewPrice = curOrigPrice - (curOrigPrice * curDiscount)
End If

   MsgBox curNewPrice

End Sub

Comments

1

Let's look here:

Dim strModelNum As String
Dim curOrigPrice As Currency
Dim sngRate As Long
Dim curDiscount As Long
Dim curNewPrice As Currency

By using longs for the discount rates, I think you are asking for trouble.

Dim strModelNum As String
Dim curOrigPrice As Currency
Dim sngRate As Double
Dim curDiscount As Double
Dim curNewPrice As Currency

1 Comment

Changing from Long to Double was all that it needed. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.