Array problem

Results 1 to 2 of 2

Thread: Array problem

  1. #1
    Join Date
    Dec 1969
    Posts
    1,324

    Default Array problem

    HI<BR>I am having a problem reading and/or writing data to a session state array. <BR><BR>My code is below, I hope it is just a typo error!<BR><BR>arrCart = Session("MyCart")<BR>scartItem = Session("cartItem")<BR><BR>scartItem = scartItem + 1<BR>redim arrcart(5,scartitem)<BR>Session("cartItem") = scartItem<BR>Set rsItem = Server.CreateObject("ADODB.Recordset")<BR>rsItem.O pen "products"<BR>rsItem.Filter = "catalogID = " & prodid<BR> If Not rsItem.EOF Then<BR> arrCart(1,1) = rsItem("CatalogID")<BR> arrCart(2,scartItem) = rsItem("ProdCode")<BR> arrCart(3,scartItem) = rsItem("ProdTitle")<BR> arrCart(4,scartItem) = CInt(quantity)<BR> arrCart(5,scartItem) = rsItem("ProdPrice")<BR> rsItem.Close<BR> dbc.Close<BR> End If<BR>Session("MyCart") = arrCart<BR>---------------------------------------------------------<BR>An example of my output is:<BR><BR>first time adding to the array-<BR>line value<BR>1 productname<BR><BR>next time-<BR>line value<BR>1<BR>2 productname<BR><BR>third time-<BR>line value<BR>1<BR>2<BR>3 productname<BR><BR><BR>PLEASE help.. I have been staring at this code for 2 days now!<BR><BR>thanks<BR>steve<BR>steve@iconimage.com <BR>

  2. #2
    John Weeflaar Guest

    Default RE: Array problem

    You&#039ll need to add Preserve to retain the previous content<BR>of data in the array.<BR><BR>redim Preserve arrcart(5,scartitem)<BR><BR>If you want to store catalogID,and quantity, you probably need to store it:<BR>arrCart(1,scartItem) = rsItem("CatalogID")<BR>...<BR>arrCart(4,scartItem) = rsItem("quantity")<BR><BR>You may want to convert into integer when you retrieve<BR>quantity data from arrCart(4, scarItem). But to store it in the <BR>array I think you can&#039t convert it into integer (array&#039s<BR>data type is the same for all cells).<BR><BR>Hope it helps.<BR><BR>John

Posting Permissions

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