Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

Select oldest record do some action then go to the next oldest record and do some action in vb.net

Hi all.

I'm working on a vb.net script in Visual Studio 2010 that needs to go through a collection of records and do some action and then move on to the next until the Quantity = 0.

Each record is a "picking order" each order has a order date, product and order amount.

Picking Order----OrderDate---Product---OrderAmount
123----04/01/2014---ABC---50
456---04/03/2014---ABC---20
789---04/05/2014---ABC---60

The Quantity field is the amount we have in stock for the product. In my example, product ABC the Quantity = 60

So, I need to be able to loop through my picking orders and begin slotting the quantity I have into each picking order beginning with the oldest one.

Using my example,

(1) I start with Quantity = 60, and apply 50 to Picking Order 123 thus closing that one. And now I have Quantity = 10
(2) Then I move on to the second oldest picking order, in this case 456, and apply the remaining Quantity of 10 to it, thus making picking order 456 have an order amount of 10.
(3) If there is only 1 picking order then apply the 50 it needs and place the remaining quantity of 10 in a field called "overage", or if there only 2 picking orders and we've closed them both out and still have some "overage" then apply that "overage" to the last blanket order (in this case the second one).

The picking orders are pulled from a query to the database:

Select * From PickingOrders Where ItemNumber = "the item number I'm analyzing"

Any idea how I can do this? I was thinking a do while loop or do until loop, but need some syntax guidance.

Thank you in advance!
ASKER CERTIFIED SOLUTION
Avatar of Kamal Khaleefa
Kamal Khaleefa
Flag of Kuwait image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial