Newbie: Nested dynamic arrays

Discussion in 'ASP General' started by Neil, Jan 11, 2004.

  1. Neil

    Neil Guest

    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
     
    Neil, Jan 11, 2004
    #1
    1. Advertising

  2. Neil

    Alex G Guest

    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.

    (Neil) wrote in message news:<>...
    > 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
     
    Alex G, Jan 12, 2004
    #2
    1. Advertising

  3. Neil

    Neil Guest

    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

    (Alex G) wrote in message news:<>...
    > 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.
    >
    > (Neil) wrote in message news:<>...
    > > 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
     
    Neil, Jan 12, 2004
    #3
  4. Neil

    Alex G Guest

    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


    (Neil) wrote in message news:<>...
    > 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
    >
    > (Alex G) wrote in message news:<>...
    > > 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.
    > >
    > > (Neil) wrote in message news:<>...
    > > > 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
     
    Alex G, Jan 13, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russ Perry Jr
    Replies:
    2
    Views:
    4,195
    Russ Perry Jr
    Aug 20, 2004
  2. Chad E. Dollins
    Replies:
    3
    Views:
    670
    Kai-Uwe Bux
    Nov 8, 2005
  3. Philipp
    Replies:
    21
    Views:
    1,160
    Philipp
    Jan 20, 2009
  4. pizzy
    Replies:
    0
    Views:
    176
    pizzy
    Mar 23, 2005
  5. pizzy
    Replies:
    5
    Views:
    394
    pizzy
    Apr 12, 2005
Loading...

Share This Page