tengo esta matriz en ASPEl aumento de tamaño de matriz dinámica
CONST CARTPID = 0
CONST CARTPRICE = 1
CONST CARTPQUANTITY = 2
dim localCart(3,20)
agrego artículos a esta matriz dinámica como esta
localCart(CARTPID,i) = productId
localCart(CARTPRICE,i) = productPrice
localCart(CARTPQUANTITY,i) = 1
El problema es, después de 4 artículos, todavía puedo añadir los elementos pero UBound siempre devuelve 3. Lo que hace que mis condiciones fallen.
Quiero aumentar el tamaño de esta matriz en tiempo de ejecución para que UBOUND pueda devolver el último valor.
Háganme saber cómo puedo hacer eso. Aquí está mi código completo
'Define constants
CONST CARTPID = 0
CONST CARTPRICE = 1
CONST CARTPQUANTITY = 2
'Get the shopping cart.
if not isArray(session("cart")) then
dim localCart(3,20)
else
localCart = session("cart")
end if
'Get product information
productID = trim(request.QueryString("productid"))
productPrice = trim(request.QueryString("price"))
'Add item to the cart
if productID <> "" then
foundIt = false
for i = 0 to ubound(localCart)
if localCart(CARTPID,i) = productId then
localCart(CARTPQUANTITY,i) = localCart(CARTPQUANTITY,i)+1
foundIt = true
exit for
end if
next
if not foundIt then
for i = 0 to 20
if localCart(CARTPID,i) = "" then
***ReDim Preserve localCart(UBound(localCart, 1) + 1,20)***
localCart(CARTPID,i) = productId
localCart(CARTPRICE,i) = productPrice
localCart(CARTPQUANTITY,i) = 1
exit for
end if
next
end if
end if
Gracias, esto funciona pero no puedo preservar los valores. Tan pronto como yo uso ReDim Preserve, me sale este error: Microsoft VBScript error de ejecución '800a0009' Subíndice fuera del intervalo /prices_test.asp, la línea 102 – VJV
muestran su código para que podamos ver que el error se está produciendo gracias – Robert
, He agregado el código completo en mi mensaje original. – VJV