469,313 Members | 2,206 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

looping of two, 2D arrays in classsic ASP

20
hello all,
i m trying to loop an 2d array with in a 2d array. it is working fine but it is not displaying as i wanted. following is my code
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim iRowLoop, iColLoop, upto
  3. For iRowLoop = 0 to UBound(mytable,2) 'Earnings row%>
  4. <tr><td width="20%">&nbsp;</td>
  5. <%    For iColLoop = 0 to UBound(mytable, 1) 'Earnings col%>
  6. <td width="20%"><span class="fc1-2"><%=mytable(iColLoop, iRowLoop)%></span></td>
  7. <%    Next
  8. Dim idednRow, idednCol
  9. For idednRow = 0 to UBound (mytable1, 2) 'deduction row
  10. For idednCol = 0 to UBound (mytable1, 1) 'deduction col%>
  11. <td width="20%"><span class="fc1-2"><%=mytable1(idednCol, idednRow)%></span></td>
  12. <%    Next 
  13.     Next
  14.  
  15. Next%>
  16. </tr>
  17.  
the inner loop is getting repeated because of the outer loop.(how to check that?) and i need to display the rows as follows
Expand|Select|Wrap|Line Numbers
  1. <tr><td>earnings</td><td>deductions</td></tr>  
  2.  
pl help me. thanx
Jun 6 '08 #1
8 2158
jeffstl
432 Expert 256MB
Just a quick response as Im short on time right now...but..

Right off the bat your </tr> is not inside your loop. So you not closing each row that your write out. That may be part of your display problems.

Also if you don't want the inner loop to repeat each time then just set up a flag.

Something like ?

Expand|Select|Wrap|Line Numbers
  1.  
  2. for loop
  3.      if MyLoop <> "False" then
  4.           for loop
  5.                'set flag
  6.                MyLoop = "False"
  7.          next
  8.      end if
  9. next
  10.  
  11.  
  12.  
Jun 6 '08 #2
yash777
20
hello jeffstl,

thank you so much for your reply.

i have solved the problem of repeating inner loop by setting the flag as you mentioned. Works fine.

the loop is giving me following result in a table.

outer loop result(Earnings)-------------------inner loop result(deductions)

BASIC --------------- 0000 ------------------- PF------- 000-------------PT ------000
HRA ------------------ 0000
LTA ------------------ 000
TA ------------------------ 000
MEDICAL
REIMBURSEMENT----000
CONVEYNACE ---------000


(the dashes are given just to understand the different cloumns)
SO, i just want that PT to come under PF.

i think i have to rearrange the loops for that.
Can you please guide me.
Jun 7 '08 #3
jeffstl
432 Expert 256MB
Can you re-post your modified code?

It sounds like you are simply writing out an extra column that you don't need to.

Double check your <td> tags, it sometimes helps to view the HTML output of the loop and see where you are generating the code incorrectly.
Jun 9 '08 #4
yash777
20
thank u for ur reply,
i think u got now what i really wanted.
following is my new code:

Expand|Select|Wrap|Line Numbers
  1.  Dim iRowLoop, iColLoop 
  2. For iRowLoop = 0 to UBound(mytable,2)'Earnings row%>
  3. <tr><td width="20%">&nbsp;</td>
  4. <%    For iColLoop = 0 to UBound(mytable, 1)'Earnings col%>
  5. <td width="20%"><span class="fc1-2"><%=mytable(iColLoop, iRowLoop)%></span></td>
  6. <%    Next
  7.  
  8. Dim idednRow, idednCol, myflag
  9. if myflag <> "false" then
  10. For idednRow = 0 to UBound (mytable1, 2)'deduction row
  11. For idednCol = 0 to UBound (mytable1, 1)'deduction col%>
  12. <td width="20%"><span class="fc1-2"><%=mytable1(idednCol, idednRow)%></span></td>
  13. <%    Next%> 
  14. <%    Next
  15. myflag = "false"
  16. end if
  17. %>
  18. </tr>
  19. <%Next%>
  20.  

i know the <td> of deduction column is repeating, but it is very difficult to get that new row of deduction as well as earnings and the respective columns to new line.

please help me...........
Jun 10 '08 #5
DrBunchman
979 Expert 512MB
Yash777,

Please can you start using the # button when writing your posts to surround your code with code tags - they make your posts much easier for everybody to read.

If you have not done so already, please take the time to read the Posting Guidelines.

Thank you,

MODERATOR
Jun 10 '08 #6
jeffstl
432 Expert 256MB
Without actually being able to test this (plus your loops are not indented) its very difficult for me to see why a unnecessary <td> is looping out.

Just look at the OUTPUT page of the HTML generated by this code, and look at your code carefully and try to see where you can remove the <td>.

Just try things out, remove a <td> and run it and see what you get, then youll start to understand how your loops are working better.
Jun 11 '08 #7
yash777
20
OK, thanx for all ur reply
will try my best . thank u again
Jun 12 '08 #8
yash777
20
Can any one please help me to sort this out.

i m not able to clear it.
please help...........................
Jun 14 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Sjoerd | last post: by
11 posts views Thread by motion musso aka: sathia | last post: by
11 posts views Thread by Bosconian | last post: by
1 post views Thread by assgar | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.