Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error when use EXIT FOR

Status
Not open for further replies.

bzeng

Programmer
Dec 11, 2003
13
JP
Hi, I want to exit the FOR loop when the rs0.EOF is true, but I got an error message.

Here is the code
--------------------------------
...
do while not rs0.EOF
%>
<tr align=center>
<%for i=1 to 4
if isNull(rs0(&quot;studentid&quot;)) then
bgcolor=&quot;white&quot;
notinclass=true
else
bgcolor=&quot;#FF9966&quot;
end if%>
<td width=25%><table border=1 bgcolor=&quot;<%=bgcolor%>&quot; bordercolor=&quot;gray&quot; width=&quot;100&quot;><tr><td> </td></tr></table><br><%=rs0(&quot;sname&quot;)%></td>
<% if rs0.EOF then
Exit For
else
rs0.movenext
end if
next%>
</tr>
<%
loop

...
--------------------------------------------

the error message is

Error Type:
ADODB.Field (0x80020009)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/HS/app/Admin/ClassStudent.asp

It seems that something to do with rs0.moveNext. the way I found out was to move &quot;rs0.movenext&quot; out of the FOR loop (nothing else is changed) and then the code works, but it doesn't give me the results I want)

--------------------------------

do while not rs0.EOF
%>

<tr align=center>

<%for i=1 to 4
if isNull(rs0(&quot;studentid&quot;)) then
bgcolor=&quot;white&quot;
notinclass=true
else
bgcolor=&quot;#FF9966&quot;
end if%>

<td width=25%><table border=1 bgcolor=&quot;<%=bgcolor%>&quot; bordercolor=&quot;gray&quot; width=&quot;100&quot;><tr><td> </td></tr></table><br><%=rs0(&quot;sname&quot;)%></td>
<% if rs0.EOF then
Exit For
else
end if
next%>
</tr>
<%
rs0.movenext

loop

--------------------------------------------


I wonder what I have done wrong...


thanks in advance


Brian
 
This is a duplicate reply to your post in the other forum

Im not sure this will achieve what you want but maybe just replacing the EXIT FOR with EXIT DO will help.

 
First off, you don't have a For loop to exit.

Second you are checking the condition at the the top of your Do loop. You won't enter the do loop if rs0.EOF is true so you if statement within the Do loop will never evaluate to true and your Exit Do will never be executed. I would just remove it altogether.

Take Care,

zemp

&quot;Show me someone with both feet on the ground and I will show you someone who can't put their pants on.&quot;
 
hi, thanks for all the replies.

I acutally figure out the problem:
I move

if isNull(rs0(&quot;studentid&quot;)) then
bgcolor=&quot;white&quot;
notinclass=true
else
bgcolor=&quot;#FF9966&quot;
end if


into the FOR loop and then it works!

here is the final code



-------------------------

do while not rs0.EOF

%>
<tr align=center>
<%for i=1 to 4
if rs0.EOF then
Exit FOR
else
if isNull(rs0(&quot;studentid&quot;)) then
bgcolor=&quot;white&quot;
notinclass=true
else
bgcolor=&quot;#FF9966&quot;
end if
response.write &quot;rs0(&quot;sname&quot;)
rs0.movenext

end if
next%>
</tr>

<%

loop

----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top