?
Solved

Increment total count in nested loops

Posted on 2014-01-24
5
Medium Priority
?
285 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 53

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 53

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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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