Need help with dictionary object.

Results 1 to 3 of 3

Thread: Need help with dictionary object.

  1. #1
    minni Guest

    Default Need help with dictionary object.

    I am learning ASP and I have encountered some problem regarding the dictionary object. I am using it to build a shopping cart(I don&#039t know whether this is a best solution for the shopping cart.)I got the following code from one of the tutorials and am trying to customize it.<BR><BR>Here is my code<BR>&#060;%dim dictCart<BR>Action = CStr(Request.QueryString("sAction"))<BR>&#039getti ng the var passed from previus page<BR>itemCode = Request.QueryString("code")<BR>itemCount = Request.QueryString("qty")<BR>&#039 Get a reference to the cart if it exists otherwise create it<BR> If IsObject(Session("cart")) Then<BR> Set dictCart = Session("cart")<BR> else<BR> Set dictCart = Server.CreateObject("Scripting.Dictionary")<BR>end if <BR><BR>Select Case Action<BR> Case "ADD" <BR> AddItemToCart Itemcode, ItemCount<BR> ShowItemsInCart Itemcode, ItemCount<BR>Case else<BR> ShowItemsInCart Itemcode, ItemCount<BR>End Select<BR><BR>&#039 Return cart to Session for storage<BR>Set Session("cart") = dictCart<BR><BR><BR>Sub AddItemToCart(iItemID, iItemCount)<BR> If dictCart.Exists(iItemID) Then<BR> dictCart(iItemID) = dictCart(iItemID) + iItemCount<BR> Else<BR> dictCart.Add iItemID, iItemCount<BR>End If<BR> <BR>End Sub<BR>%&#062;<BR><BR>I got the shopping cart part. But my problem is if the user clicks the "continue shopping" button and adds the same item diff quantity again the quantity is not updated..the o/p is as follows..<BR>when the user adds the item for the first time, it is okay..<BR>Item1 Item1Desc 2<BR>Now when the user adds the same item (qty 3 this time) again<BR>The o/p is <BR>Item1 ItemDesc 23<BR><BR>Please help me what&#039s happening?<BR>Thanks a lot! <BR><BR>

  2. #2
    KPW Guest

    Default RE: Need help with dictionary object.

    Here is what I would try:<BR><BR>Sub AddItemToCart(iItemID, iItemCount)<BR> If dictCart.Exists(iItemID) Then<BR> iQuantity = dictCart(iItemID)<BR> iQuantity = iQuantity + iItemCount<BR> dictCart(iItemID) = iQuantity<BR> Else<BR> dictCart.Add iItemID, iItemCount<BR> End If<BR>End Sub<BR><BR><BR>

  3. #3
    r.kotecha Guest

    Default RE: dictionary object - Time Bomb

    This is difficult to say but .. you can&#039t store a dictionary object as a session variable .. not unless Microsoft have recently updating the threading model of this object to both threaded. If you don&#039t understand all that completely just take my word for it you can&#039t store that object as a session variable and if you do you&#039re going to kill your webserver eventually.<BR><BR>Microsoft do provide a replace component that you can store in this way .. but it&#039s not as powerful as the dictionary object you&#039re using .. after I&#039ve had my lunch I&#039ll track down a microsoft article that explains everything .. otherwise go to msdn and search for "dictionary session application problem" or something like that.<BR><BR>Raj<BR>( - Student Learning Resources)

Posting Permissions

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