1. Senior Member
Join Date
Dec 1969
Posts
179

## Adding values to get total

I want to get the total of a bunch of values that I get from a Do While Loop.<BR><BR>More info:<BR>I have a Db that that holds numeric values in one of the fields.<BR>I perform a Do While Loop to get the values, perform some conversions on them (while they are in the loop) than what I need is to get the totals.<BR>I do hope this provides enough info.<BR>Thanks

2. Senior Member
Join Date
Dec 1969
Posts
1,765

## let me answer this one....

Adding values to get total...................<BR><BR><BR>ITS CALLED MATH.<BR><BR>Get some variables (its that little statement that looks like<BR><BR>Dim lngTotal &#039;as long. The total you want.<BR><BR> And some mathematical symbols like (but not limited to) +, -, =, * , / and do math.<BR><BR>Math is stuff like 1+1=3 and 6+9=100 and 2 * 2 = 9

3. Senior Member
Join Date
Dec 1969
Posts
179

## Let's not be rude to people.

I&#039;m trying to get the total value when the Do while Loop is complete.

4. Senior Member
Join Date
Dec 1969
Posts
276

## well...

x = 0<BR>sum = 0<BR>do while x &#060;&#062; 10<BR>&nbsp;sum = sum + 5<BR>&nbsp;x = x+1<BR>loop<BR>response.write sum<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
179

## Here is the Code

do while not rstemp.eof<BR><BR>pIdCartRow = rstemp("idCartRow")<BR>pIdProduct = rstemp("idProduct")<BR>pQuantity = rstemp("quantity")<BR>pUnitPrice = Cdbl(rstemp("unitPrice"))<BR>pDescription = rstemp("description")<BR>pSku = rstemp("sku")<BR>pdiscount = rstemp("discount")<BR>%&#062;<BR><BR>&#060;tr&#062 ;<BR>&#060;td width="50"&#062;&#060;font color="#000000"&#062;&#060;%= pQuantity%&#062;&#060;/td&#062;<BR>&#060;td width="80"&#062;&#060;font color="#000000"&#062;&#060;%= pSku%&#062;&#060;/td&#062;<BR>&#060;td width="375"&#062;&#060;font color="#000000"&#062;&#060;%= pDescription%&#062;&#060;/td&#062;<BR>&#060;td width="80"&#062;&#060;font color="#000000"&#062;<BR>&#060;%<BR>pRowPrice = Cdbl(pQuantity * (pOptionGroupsTotal + pUnitPrice))<BR><BR>&#039; discounts<BR>If pdiscount = True then<BR> discTotal = pRowPrice - (session("customer_discount") * (pRowPrice - shipmentTotal - paymentTotal) / 100)<BR>Else<BR> discTotal = pRowPrice<BR>End If<BR>%&#062;<BR>&#060;%= discTotal%&#062;<BR>&#060;/td&#062;<BR>&#060;/tr&#062;<BR><BR>&#060;%<BR>rstemp.movenext<BR>loop <BR>%&#062;<BR><BR><BR>So i want to get the total of "discTotal" after the loop is done

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## And did you do what Phreaker said?

No, you didn&#039;t.<BR><BR>*BEFORE* your DO WHILE statement, you need to initialize a grand total variable. Maybe something like this:<BR><BR>&#060;%<BR>...<BR>[hl="yellow"]grandTotal = 0.0[/hl]<BR>Do While Not rstemp.eof<BR> ...<BR>%&#062;<BR><BR>And then you need to ADD TO that grand total each time through the loop:<BR><BR>&#060;%<BR>...<BR> &#039; discounts<BR> If pdiscount = True then<BR> discTotal = pRowPrice - (session("customer_discount") * (pRowPrice - shipmentTotal - paymentTotal) / 100)<BR> Else<BR> discTotal = pRowPrice<BR> End If<BR>[hl="yellow"] grandTotal = grandTotal + discTotal[/hl]<BR> ....<BR>%&#062;<BR><BR>And then, finally, the grand total is available *after* the LOOP to be displayed as you choose.<BR><BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
179

## Thank you Bill for the further explanation.

.

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## But it's what Phreaker told you...

...honest. If you go back and look at his example.<BR><BR>You just need to learn to apply generic code to your own specific situation.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
179

## Understood.

.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•