PDA

Click to See Complete Forum and Search --> : Do --- Loop


Looster
Feb 13th, 2001, 10:48 PM
Hey guy's

Here's my code:
************
Set rsResults = conn.Execute("SELECT * FROM Headlines WHERE Head_Date = '" & lcdate & "' ORDER By Head_Index Desc")
if not rsResults.EOF then
Response.Write "</blockquote><font face=""times new roman"" size=""5"" color=""#000000"">Today's Top Stories.</font><blockquote><ul type=""disc"">"
Do
if cstr(rsResults("Head_Date")) = lcdate then
Response.Write "<li><a href=""javascript:Head('http://www.newsclip.co.za/asp/headline.asp?sHead=" & rsResults("Head_Index") & "')""><font face=""times new roman"" size=""3"" color=""RED"">" & rsResults("Head_Headline") & " <br> " & rsResults("Head_Time") & "</font></a>"
i = i + 1
rsResults.MoveNext()
else
Response.write "Error Retriving Data.<br>"
end if
Loop While i <> 4 'OR rsResults.EOF = True
end if
*******************
My problem is that if I have less than 3 headlines to be added I get an error message Now I want to loop to run 3 times or until the end of the Recordset has been reached but It doesn't want to work that way.

Thanks in advance

Feb 14th, 2001, 04:36 AM
Perhaps you can try this trick.

If Not rsResults.EOF Then
Do Until rsResults.EOF
if cstr(rsResults("Head_Date")) = lcdate then
' Place here your output code.
Else
Response.write "Error Retriving Data.<br>"
End IF
i = i + 1
rsResults.MoveNext
Loop
End If

And if you want to exit the loop you can use

If i = 3 Then
Exit Do
End If