If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Do Until blah then stop

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-01-05, 07:13
Crash1hd Crash1hd is offline
Registered User
 
Join Date: Jan 2004
Posts: 38
Do Until blah then stop

I am having trouble with the following code!

Set RSB = Conn.Execute("SELECT * FROM PetObituarys WHERE username = '" & Session("username") & "' order by Expired asc")

do until RSB.EOF
IF CDate(RSB("Expired")) <= (Date+7) OR RSB("Approved") = 0 Then
Response.write "<Font Color=Red> ATTN:"
End If
RSB.Movenext
Loop


The above code outputs the following

<Font Color=Red> ATTN:<Font Color=Red> ATTN:<Font Color=Red> ATTN:<Font Color=Red> ATTN:</Font></Font></Font></Font>

and I only want it to output
<Font Color=Red> ATTN:</Font>

no matter how many records have the criteria

Basically what is missing to tell it to stop the loop after finding the first record that matchs the criteria
Reply With Quote
  #2 (permalink)  
Old 01-01-05, 07:28
Crash1hd Crash1hd is offline
Registered User
 
Join Date: Jan 2004
Posts: 38
As always I just have to post the question to get the answer!! Argh

I realized that all I had to do was add

Dim NumChk
do until RSB.EOF OR NumChk = 1
IF CDate(RSB("Expired")) <= (Date+7) OR RSB("Approved") = 0 Then
Response.write "<Font Color=Red> ATTN:"
NumChk = NumChk + 1
End If
RSB.Movenext
Loop

and it stopped once I hit NumChk = 1 lol

Well Thanks for reading
Reply With Quote
  #3 (permalink)  
Old 01-14-05, 10:51
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
The other way is to use the statement Exit Do

<%
Do until RSB.EOF
IF CDate(RSB("Expired")) <= (Date+7) OR RSB("Approved") = 0 Then
Response.write "<Font Color=Red> ATTN:"
Exit Do
End If
RSB.Movenext
Loop
%>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On