looping of two, 2D arrays in classsic ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yash777
    New Member
    • Mar 2008
    • 20

    looping of two, 2D arrays in classsic ASP

    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
    Code:
        
    Dim iRowLoop, iColLoop, upto
    For iRowLoop = 0 to UBound(mytable,2) 'Earnings row%>
    <tr><td width="20%">&nbsp;</td>
    <%	For iColLoop = 0 to UBound(mytable, 1) 'Earnings col%>
    <td width="20%"><span class="fc1-2"><%=mytable(iColLoop, iRowLoop)%></span></td>
    <%	Next
    Dim idednRow, idednCol
    For idednRow = 0 to UBound (mytable1, 2) 'deduction row
    For idednCol = 0 to UBound (mytable1, 1) 'deduction col%>
    <td width="20%"><span class="fc1-2"><%=mytable1(idednCol, idednRow)%></span></td>
    <%	Next 
    	Next
     
    Next%>
    </tr>
    the inner loop is getting repeated because of the outer loop.(how to check that?) and i need to display the rows as follows
    Code:
    <tr><td>earnings</td><td>deductions</td></tr>
    pl help me. thanx
    Last edited by DrBunchman; Jun 9 '08, 01:33 PM. Reason: Added code tags - Please use the # button
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    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 ?

    Code:
    for loop
         if MyLoop <> "False" then
              for loop
                   'set flag
                   MyLoop = "False"
             next
         end if
    next

    Comment

    • yash777
      New Member
      • Mar 2008
      • 20

      #3
      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(deductio ns)

      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.

      Comment

      • jeffstl
        Recognized Expert Contributor
        • Feb 2008
        • 432

        #4
        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.

        Comment

        • yash777
          New Member
          • Mar 2008
          • 20

          #5
          thank u for ur reply,
          i think u got now what i really wanted.
          following is my new code:

          Code:
           Dim iRowLoop, iColLoop 
          For iRowLoop = 0 to UBound(mytable,2)'Earnings row%>
          <tr><td width="20%">&nbsp;</td>
          <%	For iColLoop = 0 to UBound(mytable, 1)'Earnings col%>
          <td width="20%"><span class="fc1-2"><%=mytable(iColLoop, iRowLoop)%></span></td>
          <%	Next
           
          Dim idednRow, idednCol, myflag
          if myflag <> "false" then
          For idednRow = 0 to UBound (mytable1, 2)'deduction row
          For idednCol = 0 to UBound (mytable1, 1)'deduction col%>
          <td width="20%"><span class="fc1-2"><%=mytable1(idednCol, idednRow)%></span></td>
          <%	Next%> 
          <%	Next
          myflag = "false"
          end if
          %>
          </tr>
          <%Next%>

          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...........
          Last edited by DrBunchman; Jun 10 '08, 10:50 AM. Reason: Added code tags - Please use the # button

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            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

            Comment

            • jeffstl
              Recognized Expert Contributor
              • Feb 2008
              • 432

              #7
              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.

              Comment

              • yash777
                New Member
                • Mar 2008
                • 20

                #8
                OK, thanx for all ur reply
                will try my best . thank u again

                Comment

                • yash777
                  New Member
                  • Mar 2008
                  • 20

                  #9
                  Can any one please help me to sort this out.

                  i m not able to clear it.
                  please help........... ............... .

                  Comment

                  Working...