Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Collections in ASP: Names vs. Numbers

Reply
Thread Tools

Collections in ASP: Names vs. Numbers

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      07-23-2003
I am using the Folder.Files collection to display all the images in a given
directory. The following shows the code I use to create and use this
collection:

Set myfilesys=Server.CreateObject("Scripting.FileSyste mObject")
Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))

When I use a specific file name to access a file, my code works fine:

<img src=" & Chr(34) & mydirectory.Name & "/" &
mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">

However, I want to iterate through all the files in the Folder USING NUMBERS
(I already know how to do it using a For Each statement). But whenever I try
to do this, I receive an error:

<img src=" & Chr(34) & mydirectory.Name & "/" & mydirectory.Files(5).Name
& Chr(34) & ">

Other collections, such as the Request.Form collection allow you to access
the collection using either text or numbers, and all books that I have read
have said that this is true for all collections. Is the Folder.Files
collection an exception to this? Is there something else I need to do? If
anybody can give me any help on this, I would appreciate it. Thank You.
--
Nathan Sokalski
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.students.kutztown.edu/soka0908/HomePage.html



 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      07-23-2003
The files collection doesn't support referencing an item by its index. Why?
There's probably a reason. But you can only reference it by its key, which
is the file name. Mind if I ask why you want to do this?

Ray at home

--
Will trade ASP help for SQL Server help


"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am using the Folder.Files collection to display all the images in a

given
> directory. The following shows the code I use to create and use this
> collection:
>
> Set myfilesys=Server.CreateObject("Scripting.FileSyste mObject")
> Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))
>
> When I use a specific file name to access a file, my code works fine:
>
> <img src=" & Chr(34) & mydirectory.Name & "/" &
> mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">
>
> However, I want to iterate through all the files in the Folder USING

NUMBERS
> (I already know how to do it using a For Each statement). But whenever I

try
> to do this, I receive an error:
>
> <img src=" & Chr(34) & mydirectory.Name & "/" &

mydirectory.Files(5).Name
> & Chr(34) & ">
>
> Other collections, such as the Request.Form collection allow you to access
> the collection using either text or numbers, and all books that I have

read
> have said that this is true for all collections. Is the Folder.Files
> collection an exception to this? Is there something else I need to do? If
> anybody can give me any help on this, I would appreciate it. Thank You.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.students.kutztown.edu/soka0908/HomePage.html
>
>
>



 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      07-23-2003
Thank you for that information. The reason I would like to use indexes
instead of keys is to make the files (which are graphics) into a table which
will automatically adjust the number of rows when more files are added to
the directory. Although I do know how to do this using a For Each loop, it
would be much simpler and more efficient if I could use indexes. But I guess
I just have to look at this as another good challenge and learning
experience. Thanks.
--
Nathan Sokalski
(E-Mail Removed)
http://www.students.kutztown.edu/soka0908/HomePage.html

"Ray at <%=sLocation%>" <(E-Mail Removed)7yasdf.com> wrote in
message news:(E-Mail Removed)...
> The files collection doesn't support referencing an item by its index.

Why?
> There's probably a reason. But you can only reference it by its key,

which
> is the file name. Mind if I ask why you want to do this?
>
> Ray at home
>
> --
> Will trade ASP help for SQL Server help
>
>
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I am using the Folder.Files collection to display all the images in a

> given
> > directory. The following shows the code I use to create and use this
> > collection:
> >
> > Set myfilesys=Server.CreateObject("Scripting.FileSyste mObject")
> > Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))
> >
> > When I use a specific file name to access a file, my code works fine:
> >
> > <img src=" & Chr(34) & mydirectory.Name & "/" &
> > mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">
> >
> > However, I want to iterate through all the files in the Folder USING

> NUMBERS
> > (I already know how to do it using a For Each statement). But whenever I

> try
> > to do this, I receive an error:
> >
> > <img src=" & Chr(34) & mydirectory.Name & "/" &

> mydirectory.Files(5).Name
> > & Chr(34) & ">
> >
> > Other collections, such as the Request.Form collection allow you to

access
> > the collection using either text or numbers, and all books that I have

> read
> > have said that this is true for all collections. Is the Folder.Files
> > collection an exception to this? Is there something else I need to do?

If
> > anybody can give me any help on this, I would appreciate it. Thank You.
> > --
> > Nathan Sokalski
> > (E-Mail Removed)
> > http://www.students.kutztown.edu/soka0908/HomePage.html
> >
> >
> >

>
>



 
Reply With Quote
 
Chris Barber
Guest
Posts: n/a
 
      07-23-2003
Populate an array and use the array indexes instead?

Chris.

"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Thank you for that information. The reason I would like to use indexes
instead of keys is to make the files (which are graphics) into a table which
will automatically adjust the number of rows when more files are added to
the directory. Although I do know how to do this using a For Each loop, it
would be much simpler and more efficient if I could use indexes. But I guess
I just have to look at this as another good challenge and learning
experience. Thanks.
--
Nathan Sokalski
(E-Mail Removed)
http://www.students.kutztown.edu/soka0908/HomePage.html

"Ray at <%=sLocation%>" <(E-Mail Removed)7yasdf.com> wrote in
message news:(E-Mail Removed)...
> The files collection doesn't support referencing an item by its index.

Why?
> There's probably a reason. But you can only reference it by its key,

which
> is the file name. Mind if I ask why you want to do this?
>
> Ray at home
>
> --
> Will trade ASP help for SQL Server help
>
>
> "Nathan Sokalski" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I am using the Folder.Files collection to display all the images in a

> given
> > directory. The following shows the code I use to create and use this
> > collection:
> >
> > Set myfilesys=Server.CreateObject("Scripting.FileSyste mObject")
> > Set mydirectory=myfilesys.GetFolder(Server.MapPath("./emoticons"))
> >
> > When I use a specific file name to access a file, my code works fine:
> >
> > <img src=" & Chr(34) & mydirectory.Name & "/" &
> > mydirectory.Files("blinkgirl.gif").Name & Chr(34) & ">
> >
> > However, I want to iterate through all the files in the Folder USING

> NUMBERS
> > (I already know how to do it using a For Each statement). But whenever I

> try
> > to do this, I receive an error:
> >
> > <img src=" & Chr(34) & mydirectory.Name & "/" &

> mydirectory.Files(5).Name
> > & Chr(34) & ">
> >
> > Other collections, such as the Request.Form collection allow you to

access
> > the collection using either text or numbers, and all books that I have

> read
> > have said that this is true for all collections. Is the Folder.Files
> > collection an exception to this? Is there something else I need to do?

If
> > anybody can give me any help on this, I would appreciate it. Thank You.
> > --
> > Nathan Sokalski
> > (E-Mail Removed)
> > http://www.students.kutztown.edu/soka0908/HomePage.html
> >
> >
> >

>
>




 
Reply With Quote
 
Michael D. Ober
Guest
Posts: n/a
 
      07-23-2003
The FileSystemObject Files Collection has a .Count property that you can
use.

Mike Ober.

"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank you for that information. The reason I would like to use indexes
> instead of keys is to make the files (which are graphics) into a table

which
> will automatically adjust the number of rows when more files are added to
> the directory. Although I do know how to do this using a For Each loop, it
> would be much simpler and more efficient if I could use indexes. But I

guess
> I just have to look at this as another good challenge and learning
> experience. Thanks.
> --
> Nathan Sokalski
> (E-Mail Removed)
> http://www.students.kutztown.edu/soka0908/HomePage.html
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting 'flat' gate level names to hierarchical names Paddy McCarthy VHDL 3 09-24-2004 05:34 PM
table field names vs. display names Bob ASP .Net 1 07-30-2004 05:06 PM
XSL rules applying to XSD (XML schema) defined type names (as opposed to node names) Lewis G. Pringle, Jr. XML 0 09-30-2003 10:34 PM
Sorting collections based on nested collections Doug Poland Java 9 09-27-2003 10:46 PM
InnerProperty Persistance for Collections containing other Collections mutex ASP .Net Building Controls 0 07-27-2003 02:45 PM



Advertisments