• Welcome to Valhalla Legends Archive.
 

Problem in Flower Pricing Program

Started by Dyndrilliac, December 02, 2003, 08:04 AM

Previous topic - Next topic

Dyndrilliac

I'm doing an assignment for class and for some reason I can't understant, all my prices round to the nearest dollar and tax isn't computed. My Code for the CalcPrice Function is below:Public Sub CalcPrice()
If Roses = True Then
   PricePlaceHolder = RosesQuant * RosesPrice
Else
   PricePlaceHolder = 0
End If
If Carnations = True Then
   PricePlaceHolder2 = CarnationsQuant * CarnationsPrice
Else
   PricePlaceHolder2 = 0
End If
If Daisies = True Then
   PricePlaceHolder3 = DaisiesQuant * DaisiesPrice
Else
   PricePlaceHolder3 = 0
End If
If Tulips = True Then
   PricePlaceHolder4 = TulipsQuant * TulipsPrice
Else
   PricePlaceHolder4 = 0
End If
Net = PricePlaceHolder + PricePlaceHolder2 + PricePlaceHolder3 + PricePlaceHolder4
Tax = Net * 0.07
Gross = Net - Tax
End Sub


My Caller is below:Private Sub cmdCalcPrice_Click()
On Error Resume Next
If chkRoses.Value = 1 Then
   Roses = True
Else
   Roses = False
End If
If chkCarnations.Value = 1 Then
   Carnations = True
Else
   Carnations = False
End If
If chkDaisies.Value = 1 Then
   Daisies = True
Else
   Daisies = False
End If
If chkTulips.Value = 1 Then
   Tulips = True
Else
   Tulips = False
End If
RosesQuant = txtRoses.Text
CarnationsQuant = txtCarnations.Text
DaisiesQuant = txtDaisies.Text
TulipsQuant = txtTulips.Text
RosesPrice = 1#
CarnationsPrice = 1.25
DaisiesPrice = 0.75
TulipsPrice = 0.5
CalcPrice
cmdMakeChange.Enabled = True
cmdCalcPrice.Enabled = False
Text1.Locked = False
txtNet.Text = Format$(Net, "Currency")
txtGross.Text = Format$(Gross, "Currency")
txtTax.Text = Format$(Tax, "Currency")
End Sub


Any help would be greatly appreciated.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Puzzle

#1

Private Sub cmdCalcPrice_Click()
Dim Price as Currency, _
Net as Currency, _
Tax as Currency, _
Gross as Currency
RosesQuant = txtRoses.Text
CarnationsQuant = txtCarnations.Text
DaisiesQuant = txtDaisies.Text
TulipsQuant = txtTulips.Text
RosesPrice = 1#
CarnationsPrice = 1.25
DaisiesPrice = 0.75
TulipsPrice = 0.5
If chkRoses.Value = 1 Then
If RoseQuant <> 0 then
Price = (RoseQuant * RosePrice)
End If
End If
If chkCarnations.Value = 1 Then
If CarnationsQuant <> 0 then
Price = (Price + (CarnationsQuant * CarnationsPrice))
End If
End If
If chkDaisies.Value = 1 Then
If DasiesQuant <> 0 then
Price = (Price + (DasiesQuant * DasiesPrice))
End If
End If
If chkTulips.Value = 1 Then
If TulipsQuant <> 0 then
Price = (Price + (TulipsQuant * TulipsPrice))
End If
End If
cmdMakeChange.Enabled = True
cmdCalcPrice.Enabled = False
Text1.Locked = False
Net = Price
Tax = (Price * .07)
Gross = (Net + Tax)
txtNet.Text = Net
txtGross.Text = Gross
txtTax.Text = Tax
End Sub


I haven't used the currency data type very much, but I'm pretty sure that will work in this case. You don't need to call CalcPrice() becuase it just adds that much more code. My example isn't much longer than your original code.

Try to avoid using On Error Resume Next. Its a catch-all error handler but it can cause unwanted results depending on the error. Try using GoTo instead and handle the error yourself.

My code isn't very clean but it should help you. I'm at school right now and if you need any more help, I will be glad to when I get home later.

EDIT: Spelling

Banana fanna fo fanna

Should define all your variables as Singles and then round.