Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Increment total count in nested loops

Posted on 2014-01-24
Medium Priority
286 Views
Hi Experts,

I expand a recordset of bookings using four nested split loops as some of the record fields contains arrays (one field contains multiple locations, one contains multiple weeknumber intervals and one contains multiple weekday names). I hereby get a list of each single bookingdate of each single room in a nice complete table.

Now I want to insert a unique counter in each of total number of rows in that table, but fail to come up with an idea of how to do it.

I'm sure some of You knows how to accomplish this.

Hope to hear from You
Best regards MortenWB

Heres the code:

``````<%
Do While Not objRec.EOF
If Alochk <> "" AND Alochk <> " " Then
a = Split(Alochk, ";")
if UBound(a) > 0 then
For q = 0 to UBound(a)
Alocn = a(q)

'SPLIT AND LOOP MULTIPLE WEEKS
b=Split(scw, ";")
for each x in b

c=Split(x, "-")
d=Split(scd, ";")
for each z in d
if z = "søndag" then scWdNr = 1
if z = "mandag" then scWdNr = 2
if z = "tirsdag" then scWdNr = 3
if z = "onsdag" then scWdNr = 4
if z = "torsdag" then scWdNr = 5
if z = "fredag" then scWdNr = 6
if z = "lørdag" then scWdNr = 7

if UBound(c) > 0 then
for y = c(0) To c(1)
y = y
response.write("" &_
"<tr valign=top>" &_
"<td><div class=tdlist style='width:320px;'>" & id & "</div></td>" &_
"<td><div class=tdlist style='width:120px;'>" & Alocn & "</div></td>" &_
"<td><div class=tdlist style='width:80px;'>u " & y & "</div></td>" &_
"<td><div class=tdlist style='width:50px;'>" & z & "</div></td>" &_
"<td><div class=tdlist style='width:100px;'>" & schdate & "</div></td>" &_"</tr>")
next
else
y = c(0)
response.write("" &_
"<tr valign=top>" &_
"<td><div class=tdlist style='width:320px;'>" & id & "</div></td>" &_
"<td><div class=tdlist style='width:120px;'>" & Alocn & "</div></td>" &_
"<td><div class=tdlist style='width:80px;'>u " & y & "</div></td>" &_
"<td><div class=tdlist style='width:50px;'>" & z & "</div></td>" &_
"<td><div class=tdlist style='width:100px;'>" & schdate & "</div></td>" &_
"</tr>")
else
end if
end if
next
next

next
else
Alocn = a(0)

'SPLIT AND LOOP MULTIPLE WEEKS
b=Split(scw, ";")
for each x in b

c=Split(x, "-")
d=Split(scd, ";")
for each z in d
if z = "søndag" then scWdNr = 1
if z = "mandag" then scWdNr = 2
if z = "tirsdag" then scWdNr = 3
if z = "onsdag" then scWdNr = 4
if z = "torsdag" then scWdNr = 5
if z = "fredag" then scWdNr = 6
if z = "lørdag" then scWdNr = 7

if UBound(c) > 0 then
for y = c(0) To c(1)
y = y
response.write("" &_
"<tr valign=top>" &_
"<td><div class=tdlist style='width:320px;'>" & id & "</div></td>" &_
"<td><div class=tdlist style='width:120px;'>" & Alocn & "</div></td>" &_
"<td><div class=tdlist style='width:80px;'>u " & y & "</div></td>" &_
"<td><div class=tdlist style='width:50px;'>" & z & "</div></td>" &_
"<td><div class=tdlist style='width:100px;'>" & schdate & "</div></td>" &_
"</tr>")
else
end if
next
else
y = c(0)
response.write("" &_
"<tr valign=top>" &_
"<td><div class=tdlist style='width:320px;'>" & id & "</div></td>" &_
"<td><div class=tdlist style='width:120px;'>" & Alocn & "</div></td>" &_
"<td><div class=tdlist style='width:80px;'>u " & y & "</div></td>" &_
"<td><div class=tdlist style='width:50px;'>" & z & "</div></td>" &_
"<td><div class=tdlist style='width:100px;'>" & schdate & "</div></td>" &_
"</tr>")
else
end if
end if
next
next

end if
Else

End IF

%>
</div>
<%

objRec.MoveNext
loop
%>
``````
0
Question by:MortenWB
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 54

Expert Comment

ID: 39806961
Your counter would be something like

``````rowCounter=0
for x = 1 to 10
rowCounter=rowCounter+1
response.write rowCounter
' or you could use x
next
``````

``````rowCounter=0
for y = c(0) To c(1)
y = y
rowCounter=rowCounter+1
response.write("" &_
"<tr valign=top>" &_
"<td><div class=tdlist style='width:320px;'>" & id & "</div></td>" &_
"<td><div class=tdlist style='width:120px;'>" & Alocn & "</div></td>" &_
"<td><div class=tdlist style='width:80px;'>u " & y & "</div></td>" &_
"<td><div class=tdlist style='width:50px;'>" & z & "</div></td>" &_
"<td><div class=tdlist style='width:100px;'>" & schdate & "</div></td>" &_"</tr>")
next
``````
Each loop will add 1 to the counter and you can use that later in your code for a total.
0

Author Comment

ID: 39807579
Thanks for answering Scott. Got sidetracked after posting, and need time to understand and implement Your suggestion, so I'll get back to You first thing in the morning.

Best regards
MortenWB
0

Author Comment

ID: 39808546
I'm back - and trying to figure it out with no luck so far. I am able to increment a counter in each separate loop, but cannot fathom how to combine them into one single consecutive I could use as an Id for each single <tr></tr> in the output.

I take the liberty of outlining my problem just to ask if I'm completely off track in my search for a solution. If real code is needed I'll of course post more of my futile attempts. But heres a sketch:

do while not ObjRec.EOF
RecordCount = RecordCount+1

if UBound(a) > 0
for each element in a

first loop
count1 = count1 + 1
<tr>response.write(count1 + RecordCount)</tr>

second loop
count2 = count2 + 1
<tr>response.write(count1 + count2 + RecordCount)</tr>

...and so on ...

else 'if UBound(a) = 0

more loops outputting <tr>RecordCounts</tr>

end if

ObjRec.movenext
loop

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

I welcome alternative thinking.

Best regards
MortenWB
0

LVL 54

Accepted Solution

Scott Fell,  EE MVE earned 2000 total points
ID: 39808567
> how to combine them into one single consecutive I could use as an Id

``````theID=0
do while not ObjRec.EOF

if UBound(a) > 0
for each element in a

first loop
theID = theID + 1
<tr>response.write(theID)</tr>

second loop
theID = theID + 1
<tr>response.write(theID)</tr>

...and so on ...

else 'if UBound(a) = 0

more loops outputting <tr>theID</tr>

end if

ObjRec.movenext
loop
``````

<table>
<!-- first loop -->
<tr>1</tr>
<table>
<!-- second loop -->
<tr>2</tr>
<tr>3</tr>
</table>
<!-- first loop -->
<tr>4</tr>
</table>
0

Author Closing Comment

ID: 39808622
Ahhhh! saved my day :) thank you Scott.

Best regards
MortenWB
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
###### Suggested Courses
Course of the Month7 days, 20 hours left to enroll