david2105
10-29-2003, 09:00 AM
Guys,
I have four arrays (COList, CodeList, AmtList, ItemList). I need to loop through the array and for each unique item in the ItemList array I need to add it into another array along with the corresponding Amt in AmtList.
If when we loop through the item array we find an existing item then we want to add the amt to the current amt in the array for that item.
This is what I have tried so far. But it doesn't work. The items in the array seem to be overwriting each other.
Does anyone have any other ideas?
Cheers,
David2105
<%
COList = CSTR(Request.Form("tCOs"))
CodeList = CSTR(Request.Form("tCodes"))
AmtList = CSTR(Request.Form("tAmts"))
ItemList = CSTR(Request.Form("tItems"))
COList = trim(Right(COList, Len(COList)-1))
CodeList = trim(Right(CodeList, Len(CodeList)-1))
AmtList = trim(Right(AmtList, Len(AmtList)-1))
ItemList = trim(Right(ItemList, Len(ItemList)-1))
COArray = Split(COList, ",")
CodeArray = Split(CodeList, ",")
AmtArray = Split(AmtList, ",")
ItemArray = Split(ItemList, ",")
ReDim ProcItemArray(1, CINT(UBOUND(COArray))+1)
ReDim ProcUsedArray(2, CINT(UBOUND(COArray))+1)
FOR k = 0 TO UBOUND(COArray)
ProcItemArray(0,k) = ""
ProcItemArray(1,k) = ""
ProcUsedArray(0,k) = ""
ProcUsedArray(1,k) = ""
ProcUsedArray(2,k) = ""
NEXT
For i = 0 TO UBOUND(ItemArray)
FOR J = 0 TO Ubound(ItemArray)
IF ProcItemArray(0,i) = "" THEN
ProcItemArray(0,i) = ItemArray(j)
END IF
IF ProcItemArray(0,i) = ItemArray(j) THEN
ProcItemArray(1,i) = cdbl(ProcItemArray(1,i) + AmtArray(j))
ELSE
ProcItemArray(0,i) = ItemArray(j)
ProcItemArray(1,i) = cdbl(AmtArray(j))
Response.Write "<h1>" & ProcItemArray(0,i) & "</h1>"
END IF
IF ProcUsedArray(0,i) = ItemArray(j) AND ProcUsedArray(1,i) = AmtArray(j) THEN
ProcUsedArray(2,i) = cdbl(ProcUsedArray(2,i) + 1)
ELSE
ProcUsedArray(0,i) = ItemArray(j)
ProcUsedArray(1,i) = cdbl(AmtArray(j))
ProcUsedArray(2,i) = 1
END IF
NEXT' J increment loop (ItemArray)
Next
%>
I have four arrays (COList, CodeList, AmtList, ItemList). I need to loop through the array and for each unique item in the ItemList array I need to add it into another array along with the corresponding Amt in AmtList.
If when we loop through the item array we find an existing item then we want to add the amt to the current amt in the array for that item.
This is what I have tried so far. But it doesn't work. The items in the array seem to be overwriting each other.
Does anyone have any other ideas?
Cheers,
David2105
<%
COList = CSTR(Request.Form("tCOs"))
CodeList = CSTR(Request.Form("tCodes"))
AmtList = CSTR(Request.Form("tAmts"))
ItemList = CSTR(Request.Form("tItems"))
COList = trim(Right(COList, Len(COList)-1))
CodeList = trim(Right(CodeList, Len(CodeList)-1))
AmtList = trim(Right(AmtList, Len(AmtList)-1))
ItemList = trim(Right(ItemList, Len(ItemList)-1))
COArray = Split(COList, ",")
CodeArray = Split(CodeList, ",")
AmtArray = Split(AmtList, ",")
ItemArray = Split(ItemList, ",")
ReDim ProcItemArray(1, CINT(UBOUND(COArray))+1)
ReDim ProcUsedArray(2, CINT(UBOUND(COArray))+1)
FOR k = 0 TO UBOUND(COArray)
ProcItemArray(0,k) = ""
ProcItemArray(1,k) = ""
ProcUsedArray(0,k) = ""
ProcUsedArray(1,k) = ""
ProcUsedArray(2,k) = ""
NEXT
For i = 0 TO UBOUND(ItemArray)
FOR J = 0 TO Ubound(ItemArray)
IF ProcItemArray(0,i) = "" THEN
ProcItemArray(0,i) = ItemArray(j)
END IF
IF ProcItemArray(0,i) = ItemArray(j) THEN
ProcItemArray(1,i) = cdbl(ProcItemArray(1,i) + AmtArray(j))
ELSE
ProcItemArray(0,i) = ItemArray(j)
ProcItemArray(1,i) = cdbl(AmtArray(j))
Response.Write "<h1>" & ProcItemArray(0,i) & "</h1>"
END IF
IF ProcUsedArray(0,i) = ItemArray(j) AND ProcUsedArray(1,i) = AmtArray(j) THEN
ProcUsedArray(2,i) = cdbl(ProcUsedArray(2,i) + 1)
ELSE
ProcUsedArray(0,i) = ItemArray(j)
ProcUsedArray(1,i) = cdbl(AmtArray(j))
ProcUsedArray(2,i) = 1
END IF
NEXT' J increment loop (ItemArray)
Next
%>