How to I rearrange this so that only distance less than or equal to 25 are displayed?

For i = 1 to 20
               Display(rs)
               rs.MoveNext
               If rs.Eof Then Exit For
               If rs("distance")>25 Then Exit For
            Next

first thing i noticed is that your comparison sign is incorrect:

If rs("distance")>25 Then Exit For

should be

If rs("distance")<25 Then Exit For

I would also change the loop, to loop till end of file instead of using the counter i, what if the records that are less than 25 are in the fileds that are not extracted by your counter.

Hope this helps a bit.

Nearly, should be...

If rs("distance")<=25 Then Exit For

...for less than or equal to. :o)

Nearly, should be...

If rs("distance")<=25 Then Exit For

...for less than or equal to. :o)

If I understand the original question, then both these response seem incorrect. My interpretation of your response is that the "loop" will stop at the first occurence of a distance < 25. The poster seem to be asking for loop that will display only distants under 25, which I interpret as " show me all the distants that are < 25.

Therefore, he must use something such as :

do while not rs.eof
if rs("distant")<25 then
response.write " display me" ' or whatever he wants to do
end if
rs.movenext
loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.