Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Ending While Loop
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Ending While Loop

 Post Reply Post Reply
Author
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Topic: Ending While Loop
    Posted: 24 September 2003 at 4:44pm

I'm building a small search engine.. I wish to have a part 1 and a part 2 alternate between each other, my only problem is that i need to make sure that i'm not at recordset.EOF within mid loop. Sample Code:

<%
   While NOT rs.eof
%>
PT1
<%
   If NOT rs.eof then
   rs.movenext
Else
   (end loop)
end if
%>
PT2
<% Wend %>
  

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 6:04pm

Ok, well why dont you use a switch variable:

Dim blnAtFirstStage
blnAtFirstStage = False

Do until rsCommon.eof
  If blnAtFirstStage = False then
    blnAtFirstStage = True
    'Do your stage one stuff
  Else
    blnAtFirstStage = False
    'Do your stage two stuff
  End if
rsCommon.movenext
Loop
rsCommon.close

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 8:52pm

<%
   While NOT rs.eof
%>
PT1
<%
   If NOT rs.eof then
   rs.movenext
Else
   (end loop)
end if
%>
PT2
<% Wend %>

besides the fact that you totally needlessly say "If NOT rs.EOF" while inside the loop that flat out says already "i am not at the end of the recordset".. making asking "am i at the end" a waste of CPU cycles :-)

Contribute to the working anarchy we fondly call the Internet
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 24 September 2003 at 8:55pm

While..Wend is kinda old school and more code than is needed...

Guillian suggested a good way, and then a new option opens up for you, "Exit Do" if you need to must out early.....

Here's more on the "Exit" statement of VBScript:
http://www.netzone.ch/caspdoc/html/vbscript_exit_statement.h tm

Contribute to the working anarchy we fondly call the Internet
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 25 September 2003 at 2:43pm
Morningz i don't think you entirely understand what i'm trying to do. I want to create a listing of all the records alternating the color of the row... I'm just having trouble figuring out how i'm going to do it.
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 25 September 2003 at 2:59pm
gullinan's switch variable thingy worked... thanks for your help
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.