473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I nest Do loops?

If so, what is wrong with this code in APS 3.0?

I open a recordset with order info. Each record contains the order header
info plus a line item from the order detail. So the recordset looks
something like this:

Orderid PartID
1 12
1 87
2 99
2 33
The web page should display as:

Order 1
Part 12
Part 87

Order 2
Part 99
Part 33
I though I could do this with the following code:
<%
Do while not rs.eof
%>

<tr>
<td>
<%Response.Writ e (rs.Fields("ord eridid") & ".")%>
</td>
</tr>
<%

id=rs.Fields("o rderid")

Do while rs.Fields("orde rid")=id ' line 119

%>

<tr>
<td>
<%Response.Writ e (rs.Fields("par tid")) %>
</td>
</tr>

<%

rs.movenext

Loop

rs.movenext

Loop
But I get this error:

Error Type:
(0x80020009)
Exception occurred.
/orders/orders.asp, line 119

Line 119 is the second Do Loop
The outer do loop works fine but when I add the inner loop it errors

Can I nest Do Loops in ASP 3.0?

What am I doing wrong here?
Nov 22 '05 #1
4 1943
Dave wrote on 12 nov 2005 in microsoft.publi c.inetserver.as p.general:
<%
Do while not rs.eof

id=rs.Fields("o rderid")

Do while rs.Fields("orde rid")=id ' line 119
rs.movenext Loop
The second rs.movenext can give an illegal rs.Fields("orde rid") at 119
at the end of the database, I suppose.
rs.movenext

Loop

you could test:

Do until rs.eof
id=rs.Fields("o rderid")
Do until rs.Fields("orde rid")<>id or rs.eof
'' give output
rs.movenext
Loop
if rs.eof then exitdoed="yes": exit do
rs.movenext
exitdoed="no"
Loop
response.write exitdoed

in the end I would use:

Do until rs.eof
id=rs.Fields("o rderid")
Do until rs.eof OR rs.Fields("orde rid")<>id
'' give output
rs.movenext
Loop
if not rs.eof then rs.movenext
Loop

NOT TESTED

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 22 '05 #2

"Dave" <da*******@news group.nospam> wrote in message
news:u1******** *****@TK2MSFTNG P10.phx.gbl...
If so, what is wrong with this code in APS 3.0?

I open a recordset with order info. Each record contains the order header
info plus a line item from the order detail. So the recordset looks
something like this:

Orderid PartID
1 12
1 87
2 99
2 33
The web page should display as:

Order 1
Part 12
Part 87

Order 2
Part 99
Part 33
I though I could do this with the following code:
<%
Do while not rs.eof
%>

<tr>
<td>
<%Response.Writ e (rs.Fields("ord eridid") & ".")%>
</td>
</tr>
<%

id=rs.Fields("o rderid")

Do while rs.Fields("orde rid")=id ' line 119

%>

<tr>
<td>
<%Response.Writ e (rs.Fields("par tid")) %>
</td>
</tr>

<%

rs.movenext

Loop

rs.movenext

Loop
But I get this error:

Error Type:
(0x80020009)
Exception occurred.
/orders/orders.asp, line 119

Line 119 is the second Do Loop
The outer do loop works fine but when I add the inner loop it errors

Can I nest Do Loops in ASP 3.0?

What am I doing wrong here?


Yes, you can nest Do loops.

I think you are running into an EOF situation. If you attempt to access a
field's value at EOF an exception will be thrown. You will probably also
encounter an exception on the second MoveNext if EOF was reached by the
first MoveNext. Although not the most graceful of solutions, try the
following:

Do While Not rs.EOF
id = rs.Fields("orde rid")
Do While rs.Fields("orde rid") = id
rs.MoveNext
If rs.EOF Then
Exit Do
End If
Loop
If Not rs.EOF Then
rs.MoveNext
End If
Loop
Nov 22 '05 #3
"Dave" wrote in message news:u1******** *****@TK2MSFTNG P10.phx.gbl...
: If so, what is wrong with this code in APS 3.0?
:
: I open a recordset with order info. Each record contains the order header
: info plus a line item from the order detail. So the recordset looks
: something like this:
:
: Orderid PartID
: 1 12
: 1 87
: 2 99
: 2 33
:
:
: The web page should display as:
:
: Order 1
: Part 12
: Part 87
:
: Order 2
: Part 99
: Part 33

This assumes something similar:

strSQL = "SELECT orderid, partid FROM tParts ORDER BY orderid, partid"
set rs = conn.Execute(st rSQL)

or a stored query/procedure: (qOrdersParts)
set rs = CreateObject("A DODB.Recordset" )
conn.qOrdersPar ts, rs

dim row, col, order, arr
if not (rs.bof or rs.eof) then
arr = rs.GetRows
prt "<table>"
order = 0
prt "<tr><td>Or der " & order & "</td></tr>"
for row = 0 to ubound(arr,2)
if arr(0, row) = order then
prt "<tr><td>Pa rt " & arr(1, row) & "</td></tr>"
else
order = arr(0, row)
prt "<tr><td>Or der " & order & "</td></tr>"
prt "<tr><td>Pa rt " & arr(1, row) & "</td></tr>"
end if
next
end if

sub prt(str)
Response.Write str & vbCrLf
end sub

It's untested but looks right at 2:30am. (O:=

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Nov 22 '05 #4
Dave:

A slightly more graceful version of my previous reply:

<%
id = Empty
Do Until rs.EOF
If rs.Fields("orde rid") <> id Then
id = rs.Fields("orde rid")
%>
<tr>
<td>
<%Response.Writ e (rs.Fields("ord erid") & ".")%>
</td>
</tr>
<%
End If
%>
<tr>
<td>
<%Response.Writ e (rs.Fields("par tid")) %>
</td>
</tr>
<%
rs.MoveNext
Loop
%>
Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
6567
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
3
1638
by: terry | last post by:
Hi, Is it legal or formal to nest tag names? My code is in the following. The <name> is nested. I used java to read the xml file but it seems to not know the nested structure. I need to write the nest structure as it is a multi-level catalog description. That means a catalog is a sub-catalog of the another. If it is illegal or not formal,...
1
6977
by: darrel | last post by:
I know you CAN'T nest templates, so what would be the logic to use otherwise? Here's what I am doing: I have a template set to match a specific node based on one of it's elements. If it finds it, it renders it. I then want to see if that node has any children. If it does have children, render that. Since I can used a nested
1
1186
by: Chad | last post by:
I want to nest a grid within a MS Treeview ASP Web Control. It seems that I cannot add controls to a nodes Controls collection, however, I can put HTMLText in the Node.Text property of a Node object. The problem is, how can I get the Html text associated with any normal Web Control? I see it has a Render method, but it seems that that will...
17
3038
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a counter within the loop declaration, for loops have always seemed to me to be about doing something a certain number of times, and not about...
10
3959
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise than 'while'? C: for(i=0; i<length; i++) python: while i < length:
3
5263
by: Steven Nagy | last post by:
Hi all, ASP.NET : Framework 2.0 - C# A recent addition to my code generater will create GridView's and ObjectDataSource's in a control (ASCX). So the code gen creates an ascx, ascx.cs, ascx.designer.cs and a stylesheet. The 3 control files are placed together.
10
2218
by: Al | last post by:
Hi all, (Apologies if this is in a FAQ somewhere, I couldn't find anything). Almost every time I do any significant amount of coding in C or C++, I end up wishing C-style comments would nest. It would make rapid debugging much more convenient (vs. #if 0/#endif or editor macros). Anyway, was this an explicit design decision, or some sort...
2
1426
kmartinenko
by: kmartinenko | last post by:
Hi, I am very new to Python and I would like to know if it is possible to nest 'for' statements? The question precipitates from a certain problem I am having with running a simple calculation on a column in a .csv file. I want to read columns from an existing .csv file and write out selected columns from the .csv file along with the new...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.