Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic noobie...calculator question VB2003

Status
Not open for further replies.

Digitalcandy

IS-IT--Management
May 15, 2003
230
0
0
US


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
 
Call up the calculator in Windows and test it out. Enter .1 and hit the "%" key and it converts it to .1%. Enter 10 and hit the "%" key and it is converted to 10%.

So, treat it as .1%.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top