Ask a Question related to ASP Database, Design and Development.
-
MyaTiX #1
Really need HELP from a GURU
Hi I'm trying to get a page working that calculates the
total cost of a product by adding a percentage tax amount
and subtracting a discount or not as the case maybe.
I have a form which the user enters the
- Discription
- number of units,
- discount in %,
- unit cost
The user can then add as meny items as they require:
EG:
(Item1)
Discription = Tree (tmprs("Desc"))
Unit = 1 (tmprs("Quantity"))
Discount = 20% (tmprs("Disc"))
Unit Cost = 100 (tmprs("UnitCost"))
(Item2)
Discription = Computer (tmprs("Desc"))
Unit = 1 (tmprs("Quantity"))
Discount = 10% (tmprs("Disc"))
Unit Cost = 1000 (tmprs("UnitCost"))
I don't know how to get a value I require??? I want to
get the total discount from this info.
I tried the code shown below, but it doesn't work for the
example shown above I get the following result:
totaldisc = 330 and it should be 120
Can someone please, please help I don't get it!
Thanks
...:: CODE ::..
if not (tmprs.eof and tmprs.bof) then
tmprs.movefirst
totalcost = 0
totaldisc = 0
grandtotal = 0
while not tmprs.eof
'response.write (tmprs("disc"))
totalcost = totalcost + (tmprs("Quantity") * tmprs
("UnitCost"))
'There is a big problem with adding discounts together
totaldisc = (totalcost / 100 * (totaldisc + (tmprs
("disc"))))
tmprs.movenext
wend
MyaTiX Guest
-
Is there a Mac / Flash guru out there?
Hi all, I've searched and posted at Mozilla forums, I've searched and posted at Mac forums, but this problem I have seems to be unique and it... -
Flash Guru needed
Interactive promotions company is seeking an experienced Flash Guru. The following describes the ideal candidate: Proficiency in all areas of... -
Looking for Contribute Guru
I have been conducting a tool evaluation of Contribute and a number of other Web Content Management / Web Publishing tools for a work related... -
Gradiant Guru - where r u?
I really don't know if this is possible in any version of Illustrator but I would like to keep this vector if possible. Checkout the logo my client... -
Control Guru Needed
I am having a hard time with setting a property on a custom server control that i am placing in a repeater. The control inherits from... -
Ray at #2
Re: Really need HELP from a GURU
If I follow you, if I order 38 items that cost $983 each and I'm getting a
13% discount (that I get to enter myself, nice!), the way to determine my
discount is:
iNumberOfItemsOrdered = 38
sngCostOfItem = 983.00
sngRaysDiscount = 0.13 '(13%)
RaysDiscountedAmount = iNumberOfItemsOrdered * sngCostOfItem *
sngRaysDiscount
WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem - RaysDiscountedAmount
''or
WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem * (1-sngRaysDiscount)
Is that the part you're having problems with or is it some coding issue?
Ray at work
"MyaTiX" <anonymous@discussions.microsoft.com> wrote in message
news:082f01c3c95a$b17f5ea0$a601280a@phx.gbl...> Hi I'm trying to get a page working that calculates the
> total cost of a product by adding a percentage tax amount
> and subtracting a discount or not as the case maybe.
>
> I have a form which the user enters the
> - Discription
> - number of units,
> - discount in %,
> - unit cost
>
> The user can then add as meny items as they require:
>
> EG:
> (Item1)
> Discription = Tree (tmprs("Desc"))
> Unit = 1 (tmprs("Quantity"))
> Discount = 20% (tmprs("Disc"))
> Unit Cost = 100 (tmprs("UnitCost"))
>
> (Item2)
> Discription = Computer (tmprs("Desc"))
> Unit = 1 (tmprs("Quantity"))
> Discount = 10% (tmprs("Disc"))
> Unit Cost = 1000 (tmprs("UnitCost"))
>
> I don't know how to get a value I require??? I want to
> get the total discount from this info.
>
> I tried the code shown below, but it doesn't work for the
> example shown above I get the following result:
>
> totaldisc = 330 and it should be 120
>
> Can someone please, please help I don't get it!
>
> Thanks
>
> ..:: CODE ::..
>
> if not (tmprs.eof and tmprs.bof) then
> tmprs.movefirst
> totalcost = 0
> totaldisc = 0
> grandtotal = 0
> while not tmprs.eof
> 'response.write (tmprs("disc"))
> totalcost = totalcost + (tmprs("Quantity") * tmprs
> ("UnitCost"))
> 'There is a big problem with adding discounts together
> totaldisc = (totalcost / 100 * (totaldisc + (tmprs
> ("disc"))))
> tmprs.movenext
> wend
>
>
Ray at Guest
-
Re: Really need HELP from a GURU
OK, that is fine but the percentage discount value in the
database is stored as 20 not 0.2 how do I convert the 20
to 0.2
The other problem is it is quite normal to have 2 items
of different things like shown in my first email so how
do I add the two discounts together in the asp code to
give me a sensiable result.
Check out my first example about the tree and the
computer!
I'm not sure how the code should look when in a loop like
this???
....:: CODE ::..
if not (tmprs.eof and tmprs.bof) then
tmprs.movefirst
totalcost = 0
totaldisc = 0
grandtotal = 0
while not tmprs.eof
'response.write (tmprs("disc"))
totalcost = totalcost + (tmprs("Quantity") * tmprs
("UnitCost"))
'There is a big problem with adding discounts together
totaldisc = (totalcost / 100 * (totaldisc + (tmprs
("disc"))))
tmprs.movenext
wend
and I'm getting a>-----Original Message-----
>If I follow you, if I order 38 items that cost $983 eachway to determine my>13% discount (that I get to enter myself, nice!), thesngCostOfItem *>discount is:
>
>iNumberOfItemsOrdered = 38
>sngCostOfItem = 983.00
>sngRaysDiscount = 0.13 '(13%)
>
>RaysDiscountedAmount = iNumberOfItemsOrdered *RaysDiscountedAmount>sngRaysDiscount
>WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem -sngRaysDiscount)>''or
>WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem * (1-some coding issue?>
>
>
>Is that the part you're having problems with or is it>
>Ray at workGuest
-
Ray at #4
Re: Really need HELP from a GURU
<anonymous@discussions.microsoft.com> wrote in message
news:08a701c3c960$cf5df2f0$a501280a@phx.gbl...Divide your database value by 100.> OK, that is fine but the percentage discount value in the
> database is stored as 20 not 0.2 how do I convert the 20
> to 0.2
I suggest creating a function to simplify things. Do you want the DISCOUNT>
> The other problem is it is quite normal to have 2 items
> of different things like shown in my first email so how
> do I add the two discounts together in the asp code to
> give me a sensiable result.
>
amount or the net total that the person will pay? I'm going to assume you
want the total discount that a person will get, as that seems to be what
you're leaning toward.
Function ReturnDiscount(ItemCost, NumberOfItems, DiscountAmount)
'''This function assumes that
'''DiscountAmount is between 0 and 100, not 0.00 and 1.00
DiscountAmount = DiscountAmount / 100
ReturnDiscount = ItemCost * NumberOfItems * DiscountAmount
End Function
if not tmprs.eof then
totalcost = 0
totaldisc = 0
grandtotal = 0
while not tmprs.eof
'response.write (tmprs("disc"))
iQuantity = tmprs("Quantity")
sngDiscount = tmprs("disc")
sngCost = tmprs("UnitCost")
grandtotal = grandtotal + ReturnDiscount(sngCost, iQuantity,
sngDiscount)
tmprs.movenext
wend
Response.Write "This customer saved $" & FormatNumber(grandtotal)
Break things out into smaller pieces when you can't get something working,
and then when you have it working, put it back together into one big chunk
if that's how you want it.
Ray at work
>
> Check out my first example about the tree and the
> computer!
>
> I'm not sure how the code should look when in a loop like
> this???
>
> ...:: CODE ::..
>
> if not (tmprs.eof and tmprs.bof) then
> tmprs.movefirst
> totalcost = 0
> totaldisc = 0
> grandtotal = 0
> while not tmprs.eof
> 'response.write (tmprs("disc"))
> totalcost = totalcost + (tmprs("Quantity") * tmprs
> ("UnitCost"))
> 'There is a big problem with adding discounts together
> totaldisc = (totalcost / 100 * (totaldisc + (tmprs
> ("disc"))))
> tmprs.movenext
> wend
>
>
>> and I'm getting a> >-----Original Message-----
> >If I follow you, if I order 38 items that cost $983 each> way to determine my> >13% discount (that I get to enter myself, nice!), the> sngCostOfItem *> >discount is:
> >
> >iNumberOfItemsOrdered = 38
> >sngCostOfItem = 983.00
> >sngRaysDiscount = 0.13 '(13%)
> >
> >RaysDiscountedAmount = iNumberOfItemsOrdered *> RaysDiscountedAmount> >sngRaysDiscount
> >WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem -> sngRaysDiscount)> >''or
> >WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem * (1-> some coding issue?> >
> >
> >
> >Is that the part you're having problems with or is it>> >
> >Ray at work
Ray at Guest
-
MyaTiX #5
Re: Really need HELP from a GURU
Thank you very much!
That worked great.
but now the my next piece of code doesn't work???
...::CODE::..
Response.Write "This customer saved $" & FormatNumber
(grandtotal)
totaltax = ((totalcost-totaldisc)/100) * TaxAmount
grandtotal = (totalcost + totaltax + numchk(rs
("ShipCost")) + numchk(rs("SurCharge"))) - totaldisc
'error correction
'On Error Resume Next
usgrandtotal = ((totalcost/exrate) + (totaltax/exrate) +
(numchk(rs("ShipCost")/exrate)) + (numchk(rs
("SurCharge")/exrate))) - (totaldisc/exrate)
If Err.Number <> 0 Then
Else
MyaTiX Guest
-
McKirahan #6
Re: Really need HELP from a GURU
"MyaTiX" <anonymous@discussions.microsoft.com> wrote in message
news:0a1a01c3c969$bd4e24f0$a301280a@phx.gbl...> Thank you very much!
>
> That worked great.
>
> but now the my next piece of code doesn't work???
>
> ..::CODE::..
>
> Response.Write "This customer saved $" & FormatNumber
> (grandtotal)
>
> totaltax = ((totalcost-totaldisc)/100) * TaxAmount
> grandtotal = (totalcost + totaltax + numchk(rs
> ("ShipCost")) + numchk(rs("SurCharge"))) - totaldisc
> 'error correction
> 'On Error Resume Next
> usgrandtotal = ((totalcost/exrate) + (totaltax/exrate) +
> (numchk(rs("ShipCost")/exrate)) + (numchk(rs
> ("SurCharge")/exrate))) - (totaldisc/exrate)
> If Err.Number <> 0 Then
>
> Else
"doesn't work" ... could you be more specific?
What does "numchk()" do?
Your may want to add ",2" to your first line; as in:
Response.Write "This customer saved $" & FormatNumber(grandtotal,2)
to show the pennies.
McKirahan Guest
-
Ray at #7
Re: Really need HELP from a GURU
What doesn't work?
Ray at work
"MyaTiX" <anonymous@discussions.microsoft.com> wrote in message
news:0a1a01c3c969$bd4e24f0$a301280a@phx.gbl...> Thank you very much!
>
> That worked great.
>
> but now the my next piece of code doesn't work???
>
> ..::CODE::..
>
> Response.Write "This customer saved $" & FormatNumber
> (grandtotal)
>
> totaltax = ((totalcost-totaldisc)/100) * TaxAmount
> grandtotal = (totalcost + totaltax + numchk(rs
> ("ShipCost")) + numchk(rs("SurCharge"))) - totaldisc
> 'error correction
> 'On Error Resume Next
> usgrandtotal = ((totalcost/exrate) + (totaltax/exrate) +
> (numchk(rs("ShipCost")/exrate)) + (numchk(rs
> ("SurCharge")/exrate))) - (totaldisc/exrate)
> If Err.Number <> 0 Then
>
> Else
Ray at Guest
-
Cowboy \(Gregory A. Beamer\) #8
Re: Really need HELP from a GURU
percentageDiscount = percentageDiscount/100
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
************************************************** ********************
Think Outside the Box!
************************************************** ********************
<anonymous@discussions.microsoft.com> wrote in message
news:08a701c3c960$cf5df2f0$a501280a@phx.gbl...> OK, that is fine but the percentage discount value in the
> database is stored as 20 not 0.2 how do I convert the 20
> to 0.2
>
> The other problem is it is quite normal to have 2 items
> of different things like shown in my first email so how
> do I add the two discounts together in the asp code to
> give me a sensiable result.
>
>
> Check out my first example about the tree and the
> computer!
>
> I'm not sure how the code should look when in a loop like
> this???
>
> ...:: CODE ::..
>
> if not (tmprs.eof and tmprs.bof) then
> tmprs.movefirst
> totalcost = 0
> totaldisc = 0
> grandtotal = 0
> while not tmprs.eof
> 'response.write (tmprs("disc"))
> totalcost = totalcost + (tmprs("Quantity") * tmprs
> ("UnitCost"))
> 'There is a big problem with adding discounts together
> totaldisc = (totalcost / 100 * (totaldisc + (tmprs
> ("disc"))))
> tmprs.movenext
> wend
>
>
>> and I'm getting a> >-----Original Message-----
> >If I follow you, if I order 38 items that cost $983 each> way to determine my> >13% discount (that I get to enter myself, nice!), the> sngCostOfItem *> >discount is:
> >
> >iNumberOfItemsOrdered = 38
> >sngCostOfItem = 983.00
> >sngRaysDiscount = 0.13 '(13%)
> >
> >RaysDiscountedAmount = iNumberOfItemsOrdered *> RaysDiscountedAmount> >sngRaysDiscount
> >WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem -> sngRaysDiscount)> >''or
> >WhatRayPays = iNumberOfItemsOrdered * sngCostOfItem * (1-> some coding issue?> >
> >
> >
> >Is that the part you're having problems with or is it>> >
> >Ray at work
Cowboy \(Gregory A. Beamer\) Guest



Reply With Quote

