I am making a retail price calculator for a school project. We are to write an application that accepts the wholesale cost and its markup percentage. We have to verify the values entered for IsValidCost are between 0 & 5000 and for IsValidMarkup are between 5 and 800. I have pasted the code I have so far, but every time I try to run it, I get the message "Please enter a price between $1.00 and $1000000."
Any help will be greatly apprecitated!
April
'Project 1 Ch6
'April McKenna
'November 17, 2008
'Challenge to create a calculator that will let a user enter the wholesale price
' and the markup percentage to get the retail price.
'Retail Price = Wholesale * (1+ Markup / 100)
Public Class Form1
' Validates wholesale cost, markup cost and calculates retail price
Private Sub btnGetRetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRetail.Click
Dim dPrice As Decimal
Dim dMarkup As Decimal
Dim dRetailPrice As Decimal
If IsValid(dPrice) Then
Call CalculateRetail(dPrice, dMarkup, dRetailPrice)
Call DisplayRetail(dRetailPrice)
End If
End Sub
Private Function IsValid(ByRef dPrice As Decimal, _
ByRef dMarkup) As Boolean
Return IsValidCost(dPrice) AndAlso _
IsValidMarkup(dMarkup)
End Function
Private Function IsValidCost(ByRef dPrice As Decimal) As Boolean
'Validates that the price entered are numeric and not negitive
Const c_dPriceLow As Decimal = 1
Const c_dPriceHigh As Decimal = 5000
Dim sMessage As String = String.Format( _
"Please enter price between {0:c} and {1:c}", _
c_dPriceLow, c_dPriceHigh)
Try
dPrice = Convert.ToDecimal(txtPrice.Text)
' Price validation
If dPrice >= c_dPriceLow And dPrice <= c_dPriceHigh Then
Return True
Else
MessageBox.Show(sMessage)
txtPrice.Focus()
txtPrice.SelectAll()
Return False
End If
Catch ex As FormatException
MessageBox.Show(sMessage)
txtPrice.Focus()
txtPrice.SelectAll()
Return False
End Try
End Function
Private Function IsValidMarkup(ByRef dMarkup As Decimal) As Boolean
'Validates that the markup entered is between 5 and 800
Const c_dMarkupLow As Decimal = 1
Const c_dMarkupHigh As Decimal = 5000
Dim sMessage As String = String.Format( _
"Please enter a mark up between {0:c} and {1:c}", _
c_dMarkupLow, c_dMarkupHigh)
Try
dMarkup = Convert.ToDecimal(txtPrice.Text)
' Price validation
If dMarkup >= c_dMarkupLow And dMarkup <= c_dMarkupHigh Then
Return True
Else
MessageBox.Show(sMessage)
txtPrice.Focus()
txtPrice.SelectAll()
Return False
End If
Catch ex As FormatException
MessageBox.Show(sMessage)
txtMarkUp.Focus()
txtMarkUp.SelectAll()
Return False
End Try
End Function
Private Sub CalculateRetail(ByVal dPrice As Decimal, _
ByRef dMarkup As Decimal, _
ByRef dRetailPrice As Decimal)
' Calculate payment amount
dRetailPrice = dPrice * (1 + dMarkup / 100)
End Sub
Private Sub DisplayRetail(ByVal dRetailPrice As Decimal)
' Display discount, tax, payment
txtRetailPrice.Text = dRetailPrice.ToString("c")
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'End the application by closing the form
Me.Close()
End Sub
End Class