Solved

Increment total count in nested loops

Posted on 2014-01-24
5
280 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
  • 3
  • 2
5 Comments
 
LVL 52

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 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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 …

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now