incomplete data in muliple dimension array

V

Vinod

Michael Kirchner said:
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
 
M

Michael Kirchner

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
 
M

Michael Kirchner

Vinod said:
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
 
M

Michael Kirchner

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
 
B

Bob Barrows [MVP]

Michael said:
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
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top