1. Junior Member
Join Date
Dec 1969
Posts
1

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Brute force...

No rocket science here; you just have to search through the array.<BR><BR>WHY is this a FUNCTION? It doesn&#039;t return any value. It should be a SUB.<BR><BR>Sub AddItem(iPartNo)<BR> &#039; this procedure adds an item to the current cart<BR> &#039; CartItems holds the number of Items*3 in the cart<BR> Dim CartItems<BR><BR> Dim iQty<BR> iQty = 1 &#039; start with this assumption!<BR><BR> &#039; get the current cart into the MyArr variable<BR> MyArr = Session("cart")<BR> &#039; if no cart exists, then the current cart will be empty and we just create the array<BR> If IsEmpty(MyArr) Then<BR> CartItems = 0<BR>[hl="yellow"] Dim MyArr<BR> ReDim MyArr(4) &#039; should do it this way or problems later[/hl]<BR> Else<BR> &#039; otherwise items exist in the cart...<BR> &#039; Is there a match on this part number already?<BR> For i = 0 To UBound(MyArr)-1 Step 4<BR> If MyArr(i+2) = iPartNo Then<BR> &#039; if match found, then use this "slot"<BR> &#039; and bump the quantity by 1<BR> MyArr(i+1) = MyArr(i+1) + iQty <BR> Session("cart") = MyArr &#039; save the results<BR> Exit Sub &#039; and we are DONE!<BR> End If<BR> Next<BR> CartItems = UBound(MyArr)<BR> ReDim Preserve MyArr(CartItems+4)<BR> End if<BR><BR> GetItemsFromDB iPartNo, iPrice, iPartName<BR> iQty = 1<BR> &#039; add the qty to the array<BR> MyArr(CartItems+1) = iQty<BR> &#039; add the part number to the array<BR> MyArr(CartItems+2) = iPartNo<BR> &#039; add the price to the array<BR> MyArr(CartItems+3) = iPrice<BR> &#039; add the part name<BR> MyArr(CartItems+4) = iPartName<BR><BR> Session("cart") = MyArr<BR><BR>End Sub<BR><BR>**************<BR><BR>This could have been written a lot more cleanly, I think, as a 2D array rather than as a 1D array.<BR><BR>

#### Posting Permissions

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