Solved

Increment total count in nested loops

Posted on 2014-01-24
5
277 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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…

744 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