calculations

1. Senior Member
Join Date
Dec 1969
Posts
213

## calculations

i&#039;m not sure how to go about this if its asp, javascript or other, so let me start here.<BR><BR>i have a list asp results<BR>&#060;% do while not rs.eof %&#062;<BR>&#060;%= fee %&#062;<BR>&#060;% rs.movenext<BR>loop %&#062;<BR><BR>that fee inevitably will be a number. Now, at the bottom, i need a &#060;%= total %&#062; field (you can guess what i need).<BR><BR>So... is this ASP, Javascript, or other and can anyone point me in the right direction.<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
884

## RE: calculations

Set total to 0 (or your base price, etc) BEFORE you begin the loop. Then, while you&#039;re still looping, add fee to the total. Should look something like this:<BR><BR>&#060;%<BR>total=0<BR>do while not rs.EOF<BR> response.write fee<BR> total=total+fee<BR> rs.MoveNext<BR>Loop<BR>Response.Write total<BR>%&#062;<BR>

3. Senior Member
Join Date
Dec 1969
Posts
2,437

## RE: calculations

VB-script should be ok<BR><BR>total = 0.0<BR>do while not rs.eof<BR>fee = rs("fee")<BR>response.write fee & "<BR>"<BR>total = total + cdbl(fee) <BR>rs.movenext<BR>loop<BR>reponse.write "Total: " & total <BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
213

## RE: calculations

i tried that and keep getting a zero for my total (but thats not true).<BR><BR>this is what i have<BR><BR>&#060;%<BR> total2 = 0.0 <BR>do while not RSList.eof <BR>InvoiceTotal = RSList("InvoiceTotal") <BR>total2 = total2 + cdbl(InvoiceTotal) <BR>RSList.movenext <BR>loop <BR>%&#062;<BR><BR>&#060;%= total2 %&#062;<BR><BR>is it a problem that earlier on the page i already ran an rslist loop. just a thaught. thanks alot

5. Senior Member
Join Date
Dec 1969
Posts
884

## Could be...

That would have something to do with it, yes. If that&#039;s the case, you&#039;re already at the end of your recordset and we need to get you back to the beginning. Shoot. (Now if I could remember how to do that.)

6. Senior Member
Join Date
Dec 1969
Posts
884

## Duh, me.

After the first loop, but before this second one, try a good ole<BR>RSList.MoveFirst and see if that doesn&#039;t help.. and if I&#039;m not nuts.. <BR><BR>Ok, well, forget that second one.

7. Senior Member
Join Date
Dec 1969
Posts
2,050

## rs.requery <nm>

The swan flies at midnight....

8. Senior Member
Join Date
Dec 1969
Posts
355

## When all else fails...

...try debugging.<BR><BR>Try response.writing the RSList("InvoiceTotal") field and let us know what it says.

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

## Why why why....

...would you run ANOTHER loop just to get this total???<BR><BR>Put the totaling code into the first loop.<BR><BR>Do *not* run another loop. Total waste of performance.<BR><BR>

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

## UGH!

If you&#039;re going to do that, you might as well issue a second SQL query that gets the total in one operation. Even *that* is better than going through the stupid loop through all the records a second time!<BR><BR>

#### Posting Permissions

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