Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested For Loops? Loop through all B's before moving to next A

Status
Not open for further replies.

Marsdbginner

Technical User
Aug 11, 2011
7
US
I'm thinking that the below code says:
-if projectID A matches projectID B then sum the LOEs for planning and testing into project A and change the same for project B to 0
-if they don't match or if the LOE is 0 then go to next B
-when B reaches max go to next A

Would the below code loop through all of the B's before moving to the next A? If not how could I do this?
Do you see any errors?


Code:
MaxInt = 500
For A = 1 To MaxInt + 1
    For B = 2 To MaxInt + 1
        If strProjectID(A) = strProjectID(B) Then
            intPlanningLOE(A) = intPlanningLOE(A) + intPlanningLOE(B)
            intTestingLOE(A) = intTestingLOE(A) + intTestingLOE(B)
            'if B added to A change planning/testing LOEs to 0
            intPlanningLOE(B) = 0
            intTestingLOE(B) = 0
            'if project IDs don't match or if the current planning/testing LOEs for B are 0 then next B
            ElseIf strProjectID(A) <> strProjectID(B) Or intPlanningLOE(B) = 0 Then
                Next B
            End If
        If B = MaxInt + 1 Then
            GoTo nextA
            End If
    Next B
nextA:
Next A


Thanks in advance! Best Forums on the web!
 
I'd usse something like this instead:
Code:
MaxInt = 500
For A = 1 To MaxInt
    For B = A + 1 To MaxInt
        If strProjectID(A) = strProjectID(B) Then
            intPlanningLOE(A) = intPlanningLOE(A) + intPlanningLOE(B)
            intTestingLOE(A) = intTestingLOE(A) + intTestingLOE(B)
            intPlanningLOE(B) = 0
            intTestingLOE(B) = 0
        End If
    Next B
Next A

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top