By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

incomplete data in muliple dimension array

P: n/a
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

Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Michael Kirchner" <mi****@gmx.de> wrote in message
news:B5***************@news2.nokia.com...
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
Jul 22 '05 #2

P: n/a
Vinod wrote:
"Michael Kirchner" <mi****@gmx.de> wrote in message
news:B5***************@news2.nokia.com...
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
Jul 22 '05 #3

P: n/a
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
Jul 22 '05 #4

P: n/a
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"
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.