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
5
Medium Priority
?
286 Views
Last Modified: 2014-01-25
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
schdate = 	dateadd("w", scWdNr-4,(dateadd("ww", y-1, 1 &"-"& 1 &"-"& 2014)))
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)
schdate = 	dateadd("w", scWdNr-4,(dateadd("ww", y-1, 1 &"-"& 1 &"-"& 2014)))
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
schdate = 	dateadd("w", scWdNr-4,(dateadd("ww", y-1, 1 &"-"& 1 &"-"& 2014)))
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)
schdate = 	dateadd("w", scWdNr-4,(dateadd("ww", y-1, 1 &"-"& 1 &"-"& 2014)))
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  
%>

Open in new window

0
Comment
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
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
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
    response.write x  ' for your 0 based array, add one.
next

Open in new window


rowCounter=0
for y = c(0) To c(1)
y = y
rowCounter=rowCounter+1
schdate = 	dateadd("w", scWdNr-4,(dateadd("ww", y-1, 1 &"-"& 1 &"-"& 2014)))
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

Open in new window

Each loop will add 1 to the counter and you can use that later in your code for a total.
0
 

Author Comment

by:MortenWB
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

by:MortenWB
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

by:
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

Open in new window


<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

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

Best regards
MortenWB
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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)

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question