Forum Moderators: open

Message Too Old, No Replies

For Loop and VehCnt

         

aax123

3:23 am on Mar 2, 2006 (gmt 0)

10+ Year Member



I can't seem to get the VehCnt correct. Comments are below in code. Any help would be greatly appreciated.
----------------------------------------
tmpRunDays=0
tmpVehCnt = 0
tmpTotLines=0

do while not rs.EOF
Response.Write "<tr>"
for i = lcount to rs.Fields.Count - 4
'-- Only need to add rs.Fields(4).Value if rs.Fields(1).Value DOES NOT equal
'-- the value in the rs.Fields(1) 's above or below it.
'-- The if statement below isn't correct.
'-- For example if rs.Fields(1).Value is 101010 and the rs.Fields(1).Value(s) above
'-- equal 101010 then only add rs.Fields(4).Value ONCE otherwise continue to add.
'-- Example:
'-- rs.Fields(1) ¦ rs.Fields(4)
'-- 234267 ¦ 5
'-- 101010 ¦ 6
'-- 101010 ¦ 6
'-- 101010 ¦ 6
'-- 234567 ¦ 5
'-- 193243 ¦ 6

'-- TotVehCnt = 34 and I want it to be 22

'-- I konw this isn't correct and this is what I need help with.
if rs.Fields(1).Value <> rs.Fields(1).Value then
tmpVehCnt = tmpVehCnt + rs(4)
else
tmpVehCnt = rs(4)
end if
'--

if i=1 then
Response.Write "<td align=middle bgcolor=#ffffff nowrap><a href=""body.asp"">"&rs.Fields(i).Value&"</a></td>"
elseif i=6 then
Response.Write "<td align=right bgcolor=#ffffff nowrap>"&formatCurrency(rs.Fields(i).Value,2)&"</td>"
elseif i = 7 or i = 8 then
Response.Write "<td align=right bgcolor=#ffffff nowrap> " _
& " "&rs.Fields(i).Value&"</td>"
else
Response.Write "<td align=right bgcolor=#ffffff nowrap>"&rs.Fields(i).Value&"</td>"
end if
next
Response.Write "</tr>"
tmpRunDays = tmpRunDays + rs(3)
tmpVehCnt = tmpVehCnt + rs(4)
tmpTotLines=tmpTotLines + rs(5)
tmpCost=tmpCost + rs(6)
rs.MoveNext
loop

Response.Write "<tr>"
Response.Write "<td align=right bgcolor=#eeeeee colspan=1></td>"
Response.Write "<td align=right bgcolor=#eeeeee>TOTALS :</td>"
Response.Write "<td align=right bgcolor=#eeeeee>"&tmpRunDays&"</td>"
Response.Write "<td align=right bgcolor=#eeeeee>"&tmpVehCnt&"</td>"
Response.Write "<td align=right bgcolor=#eeeeee>"&tmpTotLines&"</td>"
Response.Write "<td align=right bgcolor=#eeeeee>"&formatCurrency(tmpCost,2)&"</td>"
Response.Write "<td align=right bgcolor=#eeeeee></td>"
Response.Write "<td align=right bgcolor=#eeeeee></td>"

john_k

3:39 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I noticed two things:

1) lcount is never explicitly initialized nor even declared.

2) Regarding the line: if rs.Fields(1).Value <> rs.Fields(1).Value then
rs.Fields(1).Value will always equal itself (unless it's Null), so only the second half of the If-Else executes.

I just looked at it quickly, so there might be other problems.