# Subtracting values from an array ASP

Say I have an array - dim myArray(3) - that holds four values: 4,2,0,0. The total values held in the array = 6. I want to subtract 5 from the the array so the new values would be to 0,1,0,0. What is the best way to do this.

I need to subtract delivered stock from previous orders in a data table. I'm guessing putting the values into an array first and then doing the maths before updating the values again would be the best way.

Thanks,
Dan
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Business Systems Analyst , ex-Senior Application EngineerCommented:
not too sure your logic behind, but you can try this...

<%
myArray = Array(4,2,0,0)
subtract = 5

for i = 0 to ubound(myArray)
if subtract > myArray(i) then
subtract = subtract - myArray(i)
myArray(i) = 0
else
myArray(i) = myArray(i) - subtract
exit for
end if
Next
response.write join(myArray,",")

%>

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
It is probably easier to calculate:

Previous Stock - Delivered Stock = New Value

for each line of stock?
Author Commented:
An invoice/packing list is generated from Indonesia each time a shipment of furniture is made. The container might fulfil some orders and parts of others. Adding to the confusion there are five different suppliers. As soon as the furniture is shipped the company lists the furniture as stock so the sales team can start selling it.

Previous Stock - Delivered Stock = New Value. This is what I'm doing but across different placed orders (database columns). I create a temporary column in the stock table for each stock order list and when that entire order has been fulfilled then I will delete the column. Depending on how quickly the suppliers manufacture the furniture they may send for example 20 chairs which might have to be matched to more than one order.