ho questo array in ASPAumentare Array Size dinamicamente
CONST CARTPID = 0
CONST CARTPRICE = 1
CONST CARTPQUANTITY = 2
dim localCart(3,20)
aggiungo elementi da questo array dinamico come questo
localCart(CARTPID,i) = productId
localCart(CARTPRICE,i) = productPrice
localCart(CARTPQUANTITY,i) = 1
Il problema è, dopo 4 elementi, posso ancora aggiungere gli elementi ma UBound restituisce sempre 3. Che causa il fallimento delle mie condizioni.
Desidero aumentare la dimensione di questo array in fase di esecuzione in modo che UBOUND possa restituire l'ultimo valore.
Per favore fatemi sapere come posso farlo. Qui è il mio codice 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
Grazie, funziona ma non posso conservare i valori. Non appena io uso ReDim Preserve, ottengo questo errore: Microsoft VBScript errore di runtime '800a0009' Indice fuori intervallo /prices_test.asp, linea 102 – VJV
mostrare il codice in modo che possiamo vedere dove l'errore è in corso – Robert
grazie , Ho aggiunto il codice completo nel mio messaggio originale. – VJV