Newbie: Nested dynamic arrays

N

Neil

Hi Folks,

In a nutshell...

I have 6 pieces of info describing products in an array which is
carried between asp pages in session arrays.

e.g.
localcart(x,i)
For...
localcart(ProdID,i)=ProdID
localcart(Size,i)=Size
etc..
Loop

then..

session("cart")= localCart (to carry the info between pages)

This has worked fine, but I want to add options that further describe
the product. Now, depending on the product type, a different number of
options are available, determined from a recordset, e.g. length,
weight, voltage, etc. which are rendered to form elements - e.g.
length=100, weight=50 etc.

My question is this.
How can my localcart array, which contains a fixed number of fields to
identify the products in the cart, contain another dynamic array which
may have 4 to 12 pieces of additional information, depending on the
product(s) selected?

If I could have a dimension in the original array, say
localcart(Options,i), which could hold the contents of a dynamic array
localOptions(), this might help - but I can't figure out a way to do
it!

I hope this is clear - appreciate your help



NMF
 
A

Alex G

What you want to do is ReDim the array with the new number of fields
each time one is added, do a search on "ReDim Array" for more
information.
 
N

Neil

Thanks for this pointer Alex.

I understand how to redim an array - however, I'm not sure of if it is
possible for an element in one array to hold the contents of another
(<===).

e.g.
....
LocalCart(0,1) = "ProductX"
LocalCart(0,2) = "Widget"
LocalCart(0,3) = "Blue"
LocalCart(0,4) = localOptions(ProductX,i) <===
'(localOptions being a 2-dim, dynamic array)

LocalCart(1,1) = "ProductY"
LocalCart(1,2) = "Thingy"
LocalCart(1,3) = "Red"
LocalCart(0,4) = localOptions(ProductY,i) <===

....

Is it possible and what is the syntax.

Thanks for your help

Neil
 
A

Alex G

I have never tried to do this, but i assume that if:

localOptions(ProductX,i) = "Option 1"

and you then

LocalCart(0,4) = localOptions(ProductX,i)

that

LocalCart(0,4) will then hold "Option 1"

i take it this isn't what you want? because not all products will hold
the same number of options, which will result in the 2nd dimension
being different sizes?

They I would maybe do it (but seems a bit messy, probably a much
better way) would be to have the localCart array store a string with
the corresponding values in the "one-dimensional" localOptions Array,
e.g.

localCart(0,4) = "0,1,2,3"

localCart(1,4) = "4,5,6"

localOptions(0) = "option1 for Product X"
localOptions(1) = "option2 for Product X"
localOptions(2) = "option3 for Product X"
etc.....

then when you want to pull the data grab the string from localCart,
split it on the commma to form another array which you use to extract
information from localOptions

tempArray = Split(localCart(0,4))

'will write out each option for the first product
for i = 0 to UBound(tempArray)
Response.Write(localOptions(tempArray(i))
Next


I haven't tested any of this so it may possibly not work or throw some
error up.

Hope it helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top