Array problem...can't get it working?

Results 1 to 2 of 2

Thread: Array problem...can't get it working?

  1. #1
    Join Date
    Dec 1969

    Default Array problem...can't get it working?

    Hello all...<BR>I&#039;m passing along a;s the skinny...<BR><BR>I have tried to write an array but it does not work. The problem is I have a function to check the records of the array then add a new row as needed in my self-made ShoppingCart program. The problem is as there is no items in the array it chucks out a subscript error?<BR><BR>Heres the code:<BR><BR>---------global.asa---------<BR>Dim cartArray()<BR>ReDim cartArray(CART_COLUMNS, 1)<BR>Session("cartArray") = cartArray<BR>---------program------------<BR>cartArray = Session("cartArray")<BR><BR>CONST ITEM_NAME = 0<BR>CONST ITEM_ID = 1<BR>CONST USER_ID = 2<BR>CONST ITEM_PRICE = 3<BR>CONST ITEM_QUANTITY = 4<BR><BR>Function addCartElement(Cart)<BR>if CartArray(1,UBound(CartArray,2)) = "" then <BR>&#039;****line 44<BR>Redim Preserve CartArray(CART_COLUMNS,UBound(CartArray,2)+1)<BR>e nd if<BR>addCartElement = UBound(CartArray,2)<BR>End Function<BR><BR>cartItem = addCartElement(cartArray)<BR>cartArray(ITEM_NAME,c artItem) = RS("Product_Name")<BR>cartArray(ITEM_ID,cartItem) = RS("ProductID")<BR>cartArray(USER_ID,cartItem) = USERID<BR>cartArray(ITEM_PRICE,cartItem) = RS("Product_Price")<BR>cartArray(ITEM_QUANTITY,car tItem) = StrQuan <BR><BR>--------- error -----------<BR>Error Type:<BR>Microsoft VBScript runtime (0x800A0009)<BR>Subscript out of range: &#039;[number: 1]&#039;<BR>/examples/store/addproduct.asp, line 44<BR><BR>*****have marked line 44 in the program<BR><BR>Can someone here see my mistake?<BR><BR>Jim Rudnick<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Array problem...can't get it working?

    Try<BR><BR>if CartArray(1,UBound(CartArray,2)) = "" then <BR><BR>with<BR><BR>if CartArray(1,UBound(CartArray,2)-1) = "" then <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