incomplete data in muliple dimension array

Discussion in 'ASP General' started by Vinod, Feb 23, 2005.

  1. Vinod

    Vinod Guest

    "Michael Kirchner" <> wrote in message
    news:B5hTd.212$...
    > Hi everybody
    >
    > The output of my multiple dimension array is quite confusing.
    >
    > Im declaring an array, store some values in it and then I save the array
    > in a session variable. On an other page I store the data of the
    > session in a new multiple dimension array.
    >
    > All data are saved correctly in the array of the 1st page. But in the
    > new array of the 2nd page there is only one entry. Does anybody knows
    > why??? Here the code example...
    >
    >
    >
    > *****Code of the 1st page*****
    >
    > i=0
    > do while Not rs.EOF
    >
    > Redim array((i)+ 1,9)
    > array (i,1) = rs.fields("Title")
    > array(i,2)= rs.fields("Description")
    > array(i,3)= rs.fields("DocLanguage")
    > array(i,4)= rs.fields("DateCreated")
    > array(i,5)= rs.fields("Category")
    > array(i,6)= rs.fields("DateTerminated")
    > array(i,7)= rs.fields("DateVisible")
    > array(i,8)= rs.fields("Site")
    > array(i,9)= rs.fields("DocType")
    > response.write(array (i,1)) 'output is correct
    > rs.MoveNext
    > i = i+1
    > loop
    >
    >
    > *****Code of the 2nd page*****
    >
    > Arrcontent = session("content")
    > dim test
    > test = IsArray(Arrcontent)
    > response.write(test)
    > for i = 1 to UBound(Arrcontent)
    > if not Arrcontent(i,1) = "" then
    > response.write (Arrcontent(i,1)) 'output incorrect only one entry
    >
    > else
    > response.write("error") 'quite a lot of errors
    > end if
    >
    >
    > Thanks for your help...
    >
    > Greetings Michael
    >


    Hi ,

    When are the values stored into the session variable in the first page. I
    don't see it in the code any where.

    One more thing can you tell me whether in the second page you are getting
    the first record or only last record something like that.

    Regards
    Vinod
     
    Vinod, Feb 23, 2005
    #1
    1. Advertising

  2. Hi everybody

    The output of my multiple dimension array is quite confusing.

    Im declaring an array, store some values in it and then I save the array
    in a session variable. On an other page I store the data of the
    session in a new multiple dimension array.

    All data are saved correctly in the array of the 1st page. But in the
    new array of the 2nd page there is only one entry. Does anybody knows
    why??? Here the code example...



    *****Code of the 1st page*****

    i=0
    do while Not rs.EOF

    Redim array((i)+ 1,9)
    array (i,1) = rs.fields("Title")
    array(i,2)= rs.fields("Description")
    array(i,3)= rs.fields("DocLanguage")
    array(i,4)= rs.fields("DateCreated")
    array(i,5)= rs.fields("Category")
    array(i,6)= rs.fields("DateTerminated")
    array(i,7)= rs.fields("DateVisible")
    array(i,8)= rs.fields("Site")
    array(i,9)= rs.fields("DocType")
    response.write(array (i,1)) 'output is correct
    rs.MoveNext
    i = i+1
    loop


    *****Code of the 2nd page*****

    Arrcontent = session("content")
    dim test
    test = IsArray(Arrcontent)
    response.write(test)
    for i = 1 to UBound(Arrcontent)
    if not Arrcontent(i,1) = "" then
    response.write (Arrcontent(i,1)) 'output incorrect only one entry

    else
    response.write("error") 'quite a lot of errors
    end if


    Thanks for your help...

    Greetings Michael
     
    Michael Kirchner, Feb 24, 2005
    #2
    1. Advertising

  3. Vinod wrote:

    > "Michael Kirchner" <> wrote in message
    > news:B5hTd.212$...
    >
    >>Hi everybody
    >>
    >>The output of my multiple dimension array is quite confusing.
    >>
    >>Im declaring an array, store some values in it and then I save the array
    >> in a session variable. On an other page I store the data of the
    >>session in a new multiple dimension array.
    >>
    >>All data are saved correctly in the array of the 1st page. But in the
    >>new array of the 2nd page there is only one entry. Does anybody knows
    >>why??? Here the code example...
    >>
    >>
    >>
    >>*****Code of the 1st page*****
    >>
    >>i=0
    >>do while Not rs.EOF
    >>
    >>Redim array((i)+ 1,9)
    >>array (i,1) = rs.fields("Title")
    >>array(i,2)= rs.fields("Description")
    >>array(i,3)= rs.fields("DocLanguage")
    >>array(i,4)= rs.fields("DateCreated")
    >>array(i,5)= rs.fields("Category")
    >>array(i,6)= rs.fields("DateTerminated")
    >>array(i,7)= rs.fields("DateVisible")
    >>array(i,8)= rs.fields("Site")
    >>array(i,9)= rs.fields("DocType")
    >>response.write(array (i,1)) 'output is correct
    >>rs.MoveNext
    >>i = i+1
    >>loop
    >>
    >>
    >>*****Code of the 2nd page*****
    >>
    >>Arrcontent = session("content")
    >>dim test
    >>test = IsArray(Arrcontent)
    >>response.write(test)
    >>for i = 1 to UBound(Arrcontent)
    >>if not Arrcontent(i,1) = "" then
    >>response.write (Arrcontent(i,1)) 'output incorrect only one entry
    >>
    >>else
    >>response.write("error") 'quite a lot of errors
    >>end if
    >>
    >>
    >>Thanks for your help...
    >>
    >>Greetings Michael
    >>

    >
    >
    > Hi ,
    >
    > When are the values stored into the session variable in the first page. I
    > don't see it in the code any where.
    >
    > One more thing can you tell me whether in the second page you are getting
    > the first record or only last record something like that.
    >
    > Regards
    > Vinod
    >
    >

    Yes in the first Page. Sorry I did not add it..



    session ("content") = array 'on the first page
     
    Michael Kirchner, Feb 24, 2005
    #3

  4. > One more thing can you tell me whether in the second page you are getting
    > the first record or only last record something like that.


    It is the last record.

    BR Michael
     
    Michael Kirchner, Feb 24, 2005
    #4
  5. Michael Kirchner wrote:
    > Hi everybody
    >
    > The output of my multiple dimension array is quite confusing.
    >
    > Im declaring an array, store some values in it and then I save the
    > array in a session variable. On an other page I store the data of the
    > session in a new multiple dimension array.
    >
    > All data are saved correctly in the array of the 1st page. But in the
    > new array of the 2nd page there is only one entry. Does anybody knows
    > why??? Here the code example...
    >
    >
    >
    > *****Code of the 1st page*****
    >
    > i=0
    > do while Not rs.EOF
    >
    > Redim array((i)+ 1,9)


    This statement is not legal syntax. Are you using On Error Resume Next to
    suppress the error message?
    Anyways, with a multidimensional array, the only dimension that can be
    resized is the last dimension. If you wish to use this time-consuming and
    processor-intensive technique to build your array, then you need to swap the
    meanings of the dimensions: use the first dimension to denote the column,
    and the second dimension to denote the row. Like this ("array" is the name
    of a builtin vbscript function, and therefore should be avoided when naming
    your variables):

    dim arData(), i, rownum
    'don't forget, array indexes are zero-based. You shouldn't
    'create an array that is larger than what you need
    do while Not rs.EOF
    rownum=rs.AbsolutePosition - 1
    redim Preserve arData(8,rownum)
    ' another improvement - use a loop to write the data into the array:
    for i = 0 to 8
    arData(i, rownum) = rs(i).value
    next
    rs.movenext
    loop

    Having said that, I must point out that you are doing this the hard way, not
    only in terms of writing the code, but also in terms of resource-usage and
    performance (recordset loops are SLOW). Your array can be built with a
    single line of code:

    dim arData
    If not rs.EOF Then arData=rs.GetRows

    When accessing the data in the array, just be aware that the indexes are
    zero-based. To read the data in the 4th field in the 5th row, use:
    arData(3,4)

    You can aid your memory by using constants:

    const cDescription = 0 ,cTitle = 1, ...

    So to read the title in the 6th row:
    arData(cTitle, 5)


    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Feb 24, 2005
    #5
    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. Ying

    muliple datagrids on one page.

    Ying, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    388
  2. Darrel

    updating muliple records

    Darrel, Oct 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    449
    Darrel
    Oct 30, 2004
  3. Replies:
    9
    Views:
    434
    John Saunders
    Dec 11, 2004
  4. Dano
    Replies:
    1
    Views:
    1,777
    Nathan Sokalski
    Feb 11, 2006
  5. Luuk
    Replies:
    15
    Views:
    832
    Nobody
    Feb 11, 2010
Loading...

Share This Page