Results 1 to 2 of 2

Thread: Looping through Array Logic

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    Looping through Array Logic

    I have an interesting problem, that I have been attempting to solve for weeks.
    I have 3 arrays
    1 array is for tracking numbers
    1 array is for products
    1 array is for product Quantities

    I have to code a solution that will "fill" the boxes. I have been able to code all of the scenarios except for when there are more boxes than products.
    So I have the following:

    Code:
    Dim PackagesArray(4), OffersArray(2), QTYArray(2)
    
    OffersArray(0) = "Line Item 1"
    OffersArray(1) = "Line Item 2"
    OffersArray(2) = "Line Item 3"
    
    
    QTYArray(0) = 3
    QTYArray(1) = 7
    QTYArray(2) = 3
    
    PackagesArray(0) = "Tracking 1"
    PackagesArray(1) = "Tracking 2"
    PackagesArray(2) = "Tracking 3"
    PackagesArray(3) = "Tracking 4"
    PackagesArray(4) = "Tracking 5"
    What I am attempting to output is

    [Tracking 1]
    Line Item 1 - 2

    [Tracking 2]
    Line Item 1 - 1
    Line Item 2 - 1

    [Tracking 3]
    Line Item 2 - 2

    [Tracking 4]
    Line Item 2 - 2

    [Tracking 5]
    Line Item 2 - 2
    Line Item 3 - 3

    Basically divide up the items and "Put" them into a box and put the remaining items into the last box.

    Below is my test code and I can't seem to figure out how to accomplish this. Any pointers would be helpful.

    Code:
    LineItems = Ubound(OffersArray)
    For a = 0 To Ubound(OffersArray)
    	TotalQty = TotalQty+QTYArray(a)
    Next
    
    BoxTotal = 0
    PackNum = 0 'Package Number
    wscript.echo "Total Items: " & TotalQty
    ItemsPerBox = fix(TotalQty/Boxes)
    wscript.echo "ItemsPerBox: " & ItemsPerBox
    wscript.echo Ubound(PackagesArray)
    
    For i = 0 To Ubound(OffersArray)
    	LeftOver = QTYArray(i) Mod ItemsPerBox
    	LineBoxes = fix(QTYArray(i)/ItemsPerBox)
    		
    	QTY = QTYArray(i)
    	
    	Do Until QTY = 0
    		
    		'wscript.echo "SpaceLeft: " & SpaceLeft
    		'Check to see if the last box and the last item
    		If PackNum = Ubound(PackagesArray) Then
    			
    		End If
    		If QTY < ItemsPerBox Then
    			If BoxTotal = 0 Then
    				wscript.echo "   "
    				wscript.echo "[=="& PackagesArray(PackNum) & "==]"
    			End If
    			wscript.echo "(" & QTY &")"& OffersArray(i) & "------"
    			BoxTotal = Boxtotal + QTY
    			QTY=QTY-QTY
    		ElseIf QTY > ItemsPerBox AND BoxTotal > 0 Then
    			SpaceLeft = ItemsPerBox - BoxTotal
    			If SpaceLeft > QTY Then
    				wscript.echo "(" & QTY & ")" & OffersArray(i) & "!!!!!!"
    				BoxTotal = BoxTotal + QTY
    				Qty= 0
    			Else
    				wscript.echo "(" & SpaceLeft & ")" & OffersArray(i) & "^^^^^^"
    				BoxTotal = 0
    				PackNum = PackNum+1
    				Qty=Qty - SpaceLeft
    				'QTY=0
    			End If
    		Else			
    			If PackNum = Ubound(PackagesArray) Then
    				wscript.echo "   "
    				wscript.echo "[==" & PackagesArray(PackNum) & "==]"				
    				'BoxTotal = BoxTotal
    				wscript.echo "(" & QTY &")" & OffersArray(i) & ">>>>>>"
    				QTY=QTY-QTY
    			Else
    				wscript.echo "   "
    				wscript.echo "[==" & PackagesArray(PackNum) & "==]"
    				wscript.echo "(" & ItemsPerBox & ")" & OffersArray(i) & "*******"
    				
    				BoxTotal = 0
    				QTY=QTY - ItemsPerBox
    				If Packnum=Ubound(PackagesArray) Then				
    					PackNum = PackNum
    				Else
    					PackNum = Packnum+1
    				End If 
    			End If
    			
    		End If 
    	Loop	
    Next
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    Resolved Re: Looping through Array Logic

    We've actually decided to go in a different direction with this project.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width