looping calculation question

1. Senior Member
Join Date
Dec 1969
Posts
310

## looping calculation question

I have a database table, which I loop through as follows:<BR><BR>----------------<BR><BR>&#060;% <BR>dim countRS <BR>countSQL = "SELECT fldCount, fldDate, fldTime FROM COUNT" <BR>set countRS = bConn.Execute(countSQL) <BR>%&#062; <BR>&#060;TABLE width="400"&#062; <BR> &#060;TR bgcolor="#000000"&#062; <BR> &#060;TH&#062;Hits&#060;/TH&#062; <BR> &#060;TH&#062;Date&#060;/TH&#062; <BR> &#060;TH&#062;Time&#060;/TH&#062; <BR> &#060;/TR&#062; <BR> &#060;% <BR>do while NOT countRS.EOF <BR>%&#062; <BR> &#060;TR&#062; <BR> &#060;TD&#062;&#060;%=countRS("fldCount")%&#062;&# 060;/TD&#062; <BR> &#060;TD&#062;&#060;%=countRS("fldDate")%&#062;&#0 60;/TD&#062; <BR> &#060;TD&#062;&#060;%=countRS("fldTime")%&#062;&#0 60;/TD&#062; <BR> &#060;/TR&#062; <BR> &#060;% <BR>countRS.MoveNext <BR>Loop <BR>%&#062; <BR>&#060;/TABLE&#062; <BR><BR>-------------------------<BR><BR>What I need to do is to be able, for each row, to work out the difference between the countRS("fldCount") value. So for e.g. if the value on row 5 = 50 and on row 60 it is 60, I want to return 10 and so on, just to work out the difference between each row as I loop through the table. <BR><BR>I can&#039;t work out how to do it though. I know I need to subtract the value of fldCount from itself each time through the loop, but each time I&#039;d need to assign the value of fldCount to a variable, and then do something like:<BR><BR>Var_diff = fldCount - what_it_was_last_time<BR><BR>But I cannot figure out how/when to assign the what_it_was_last_time variable!<BR><BR>Thanks<BR><BR>Jim<BR>

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## Something like...

&#060;% <BR>dim countRS <BR>countSQL = "SELECT fldCount, fldDate, fldTime FROM COUNT" <BR>set countRS = bConn.Execute(countSQL) <BR>%&#062; <BR>&#060;TABLE width="400"&#062; <BR>&#060;TR bgcolor="#000000"&#062; <BR>&#060;TH&#062;Hits&#060;/TH&#062; <BR>&#060;TH&#062;Date&#060;/TH&#062; <BR>&#060;TH&#062;Time&#060;/TH&#062; <BR>&#060;th&#062;Difference&#060;/th&#062;<BR>&#060;/TR&#062; <BR>&#060;% <BR>Dim PreviousValue, theDifference<BR>PreviousValue = 0<BR>do while NOT countRS.EOF <BR>%&#062; <BR>&#060;TR&#062; <BR>&#060;TD&#062;&#060;%=countRS("fldCount")%&#06 2;&#060;/TD&#062; <BR>&#060;TD&#062;&#060;%=countRS("fldDate")%&#062 ;&#060;/TD&#062; <BR>&#060;TD&#062;&#060;%=countRS("fldTime")%&#062 ;&#060;/TD&#062;<BR>&#060;%<BR>if IsNumeric(countRS("fldCount")) then<BR> theDifference = CDbl(count("fldCount")) - PreviousValue<BR> PreviousValue = CDbl(count("fldCount"))<BR>else<BR> theDifference = PreviousValue<BR> PreviousValue = 0<BR>end if<BR>%&#062;<BR>&#060;td&#062;&#060;%=theDifferen ce%&#062;&#060;/td&#062; <BR>&#060;/TR&#062; <BR>&#060;% <BR>countRS.MoveNext <BR>Loop <BR>%&#062; <BR>&#060;/TABLE&#062; <BR><BR><BR>Craig.

#### Posting Permissions

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