Hello. Yes you can subtract inside the loop, you can do what ever inside any loop. The type of loop does not decide what can be done inside the loop, it is not connected in any way.
To be honest I can not see any issue with your code, in fact it does work and displays the correct result for me. I would say there is a simple issue somewhere, maybe the placement of <% = HowMany1Tot %>. I suggest you place a simple response.write inside your loop and trace it from there. here is me usin your code whith these response.writes in place. I have added a query of my own but otherwise its all your code:
Code:
dim HowMany1Tot, rs
strsql = "select Top 14 obsDate, currentScore from diseaseScores where diseaseID=1 AND pCode=2640 order by obsDate desc;"
set rs = conn.execute(strsql)
HowMany1Tot = 0
While not rs.eof
HowMany1Tot = (HowMany1Tot + rs("currentScore"))
response.write HowMany1Tot & " = my increasing running total<bR>"
Rs.Movenext
Wend
response.write HowMany1Tot & " = my increasing grandTotal<bR><br>"
Rs.MoveFirst
HowMany1Tot = 129
While not rs.eof
HowMany1Tot = (HowMany1Tot - rs("currentScore"))
response.write HowMany1Tot & " = my decreasing running total<bR>"
Rs.Movenext
Wend
response.write HowMany1Tot & " = my decreasing grandTotal<bR><br>"
I am more a fan of using the getRows method to place a record set into an array. Its a very very efficient way of looping. Also notice the position of set rs = nothing. It means your record set is using local memory and not connected the the database. This makes large record sets load three times faster on the page. here is an example using your code:
Code:
dim HowMany1Tot, rs, myArray, i
strsql = "select Top 14 currentScore from diseaseScores where diseaseID=1 AND pCode=2640 order by obsDate desc;"
set rs = conn.execute(strsql)
HowMany1Tot = 0
myArray = rs.getRows()
se rs = nothing
for i = 0 to uBound(myArray, 2)
HowMany1Tot = (HowMany1Tot + myArray(0,i))
response.write HowMany1Tot & " = my increasing total<bR>"
next
response.write HowMany1Tot & " = my increasing GrandTotal<bR><br>"
HowMany1Tot = 129
for i = 0 to uBound(myArray, 2)
HowMany1Tot = (HowMany1Tot - myArray(0,i))
response.write HowMany1Tot & " = my decreasing total<bR>"
next
response.write HowMany1Tot & " = my decreasing GrandTotal<bR><br>"