Dybamically growing Arrays

Results 1 to 4 of 4

Thread: Dybamically growing Arrays

  1. #1
    Giles Bentley Guest

    Default Dybamically growing Arrays

    I&#039m building a shopping cart. The user will click on a product and it will be place the product info in a session variable array. I can&#039t give this array a size though because I don&#039t know how many products will be selected. Is it alright to initialise an array like this array(i,3)? where i is a value that changes

  2. #2
    BAHEK Guest

    Default RE: Dybamically growing Arrays

    I&#039ve never done this in ASP but with VB you can use Redim Preserve to change the ubound of any dimension except last one ( or something like that ) in dynamic array.<BR><BR>Exmpl:<BR>Dim aArr()<BR><BR>Redim Preserve aArr(0,1)<BR>aArr(0,0)="1"<BR>aArr(0,1)="X123"<BR> Redim Preserve aArr(ubound(aArr,1)+1,1)<BR>aArr(1,0)="2"<BR>aArr( 1,1)="Z543"<BR><BR>etc...<BR>I&#039m pretty sure this should work

  3. #3
    Steve Cimino Guest

    Default Wrong!

    From the help file:<BR><BR>If you use the Preserve keyword, you can resize only the last array dimension and you can&#039t change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.<BR><BR>ReDim X(10, 10, 10)<BR>. . .<BR>ReDim Preserve X(10, 10, 15)<BR><BR>Similarly, when you use Preserve, you can change the size of the array only by changing the upper bound; changing the lower bound causes an error.<BR><BR>

  4. #4
    BAHEK Guest

    Default RE: Wrong!

    well, like I mentioned earlyer:"( or something like that ) "<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