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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding values

Status
Not open for further replies.

ProTouch

Programmer
Jul 10, 2002
10
US
I am creating a "shopping cart" where I need to add the subtotals into a total.
The following code is in a loop for a recordset based on the items the customer has ordered. On occasion an item is priced differently if bought in a different quantity, which is why there are the different prices and quantities.
The result is a subtotal for the quatity of products ordered. How can I add all of these subtotals into a total?
<%
IF RS(&quot;txtprice&quot;) <> &quot;&quot; then
subtotal= (RS(&quot;txtquantity&quot;))*(RS(&quot;txtprice&quot;))
subtotal= formatcurrency(subtotal ,2)
response.write &quot;&quot; & subtotal &&quot;&quot;
else
response.write &quot;&quot;
end if

IF RS(&quot;txtprice2&quot;) <> &quot;&quot; then
subtotal= (RS(&quot;txtquantity2&quot;))*(RS(&quot;txtprice2&quot;))
subtotal= formatcurrency(subtotal ,2)
response.write &quot;&quot; & subtotal &&quot;&quot;
else
response.write &quot;&quot;
end if

IF RS(&quot;txtprice3&quot;) <> &quot;&quot; then
subtotal= (RS(&quot;txtquantity3&quot;))*(RS(&quot;txtprice3&quot;))
subtotal= formatcurrency(total ,2)
response.write &quot;&quot; & subtotal &&quot;&quot;
else
response.write &quot;&quot;
end if

IF RS(&quot;txtprice4&quot;) <> &quot;&quot; then
subtotal= (RS(&quot;txtquantity4&quot;))*(RS(&quot;txtprice4&quot;))
subtotal= formatcurrency(total ,2)
response.write &quot;&quot; & subtotal &&quot;&quot;
else
response.write &quot;&quot;
end if

%>
 
each time you have a new value add the string to a string containing the total value of everything..


strOverAllTotal = strOverAllTotal + strNewPrice

strOverAllTotal = strOverAllTotal + strNewPrice2

Response.Write &quot;Your cart total is: &quot; & strOverAllTotal


www.vzio.com
ASP WEB DEVELOPMENT



 
if those your quotation is in your loop, then it would be easy to get you total amount.

Code:
GrandTotal = 0
Do while RS.eof
   'your codes here ...... in order to get the subtotal.
   
   'increment your total with your subtotal
   GrandTotal = GrandTotal + subtotal
   RS.movenext
Loop

response.write &quot;Grand Total : &quot; & formatcurrency(GrandTotal,2)

is it what u mean ??

*JJ26* :eek:)
 
That answered my questtion. Thank you for the quick reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top