Digitalcandy
IS-IT--Management
For my VB class I have to make a simple calculator. One of the inputs is percentage discounted.
If someone enters .10 into the percentage discounted text box should I treat it as .10% or convert it to 10%?
Here is my VB code for reference.
____________________________________________________
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim PD, OP, DPPI, OC, DC As Double
Dim NoIP As Integer
OP = CDbl(txtOP.Text)
PD = CDbl(txtPD.Text)
NoIP = CInt(txtNoIP.Text)
DPPI = DiscountPrice(OP, PD)
OC = OriginalCost(OP, NoIP)
DC = DPPI * NoIP
If PD >= 1 Then
PD = PD / 100
End If
txtDPPI.Text = FormatCurrency(DPPI)
txtOC.Text = FormatCurrency(OC)
txtDC.Text = FormatCurrency(DC)
txtOP.Text = FormatCurrency(OP)
txtPD.Text = FormatPercent(PD, 2)
End Sub
Function DiscountPrice(ByVal OP As Double, ByVal PD As Double) As Double
Dim DPPI As Double
Select Case PD
Case Is < 1
DPPI = OP * (1 - PD)
Case Else
DPPI = OP * (1 - (PD / 100))
End Select
Return DPPI
End Function
Function OriginalCost(ByVal OP As Double, ByVal NoIP As Double) As Double
Dim OC As Double
OC = OP * NoIP
Return OC
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtOP.Text = ""
txtPD.Text = ""
txtNoIP.Text = ""
txtDPPI.Text = ""
txtOC.Text = ""
txtDC.Text = ""
End Sub
End Class