write an application to determine a markup cost. must contain a function called CalculateRetail
when clicking a "get retail" button, (btnCalc) program should..
verify values are positive
call the calculateretail function
display retail cost as displayed by function
basically, if wholesale is $5, markup is 100%, it should show price as $10
so there are 3 boxes.
textbox 1 = txtWholesale
textbox 2 = txtMarkup
Label 1 = lblRetail
must use option strict
TRY / CATCH cannot be used.
must show if input is numeric
must have a "clear" button to clear all boxes
here is my code which i am sure has all sorts of issues as i am apparently not very good at VB... decent enough with HTML but for some reason, VB is hard for me.
Option Strict On
Public Class Form1
Private decWholesale As Decimal 'to hold wholesale price
Private decMarkupPrice As Decimal 'to hold markup %
Private DecMarkup As Decimal
Private Function Validatefields() As String
'Give message if not numeric and under 1 as a whole number
If IsNumeric(txtWholesale.Text) Then
lblWarning.Text = "Wholesale Price must be numeric and whole number"
Return CStr(False)
End If
If IsNumeric(txtMarkup.Text) Then
lblWarning.Text = "Markup amount must be numeric and whole number"
Return CStr(False)
End If
Return CStr(True)
End Function
Function CalculateRetail(ByVal decretail As Decimal, ByVal decMarkup As Decimal) As Decimal
'calculate and return markup price
Dim decMarkupPrice As Decimal
Dim decPercentage As Decimal
decPercentage = CDec(decMarkup * 0.01)
decMarkupPrice = decWholesale + (decWholesale * decPercentage)
Return decMarkupPrice
End Function
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim decMarkupPrice As Decimal
'clear previous warning
lblWarning.Text = String.Empty
txtWholesale.Text = String.Empty
txtMarkup.Text = String.Empty
'input fields if valid
If Validatefields() Then
decMarkupPrice = CalculateRetail(decWholesale, decMarkup)
lblRetail.Text = decMarkupPrice.ToString("c")
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'clear previous messages
lblWarning.Text = String.Empty
txtWholesale.Text = String.Empty
txtMarkup.Text = String.Empty
End Sub
End Class
if you need any other info or anything, just let me know. i am just lost right now.
Question
Kristopher Howe
I am having some major issues. The assignment
write an application to determine a markup cost. must contain a function called CalculateRetail
when clicking a "get retail" button, (btnCalc) program should..
verify values are positive
call the calculateretail function
display retail cost as displayed by function
basically, if wholesale is $5, markup is 100%, it should show price as $10
so there are 3 boxes.
textbox 1 = txtWholesale
textbox 2 = txtMarkup
Label 1 = lblRetail
must use option strict
TRY / CATCH cannot be used.
must show if input is numeric
must have a "clear" button to clear all boxes
here is my code which i am sure has all sorts of issues as i am apparently not very good at VB... decent enough with HTML but for some reason, VB is hard for me.
if you need any other info or anything, just let me know. i am just lost right now.
Link to comment
Share on other sites
16 answers to this question
Recommended Posts