Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

files collection

Status
Not open for further replies.

motte

Programmer
May 31, 2001
155
US
Hi,

I have a problem. I have a files collection. It holds all the files in a directory. I want to be able to only print out the first 5. I've tried to add the element numbers to the collection, but I get an error. Is there a way to access different elements in a collection w/o having to loop thru and see every one of them?

Mike

Below is the section of code that gives me problems. I can loop thru and print them all, but I don't want that.
############################################################
set array2=obfolder.Files

'This line here won't work. How can I access the first one?
response.write(&quot;<h2><b>&quot; & array2(0) & &quot;</b></h2>&quot;)

for each file in array2
response.write(&quot;<img src=graphics/&quot; & file.name & &quot; width=50 height=50 alt=&quot; & file.name &&quot;>&quot;)
response.write(file.name&&quot;<br>&quot;)
next
############################################################
 
&quot;set array2=obfolder.Files&quot;
Array2 is not an array just beacuse you called it array. The SET causes it to be an object, in this case, a Files Collection. Collections are numbered from 1. That is why array2(0) fails.

 
Ok, I'm back. Here is a better version of it: (I do know calling something an array won't make it one. I read that the collection is returned in an array. So to make it simple, I just named it that.)
############################################################
dim array3()
dim totalpics
totalpics=0

for each file in array2
'array2 is the collection of filenames
redim array3(totalpics)
array3(totalpics)=file.name
totalpics=totalpics+1
next
response.write(&quot;<b>There are &quot; & totalpics & &quot; pictures in the directory</b><br>&quot;)

response.write(&quot;<h2><b>first element is &quot; & array3(0) & &quot; </b></h2>&quot;)
###########################################################
This almost works. The array3(0) doesn't display anything. but array3(143) does since there are 144 pics in the directory. This should make the first element equal to the first file in the collection, the second equal to the second, all the way to the last one. But no names appear for the elements, except the last one...any ideas?

Mike
 
never mind. i figured it out.
thanks for the help anyways.
mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top