473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Collections in ASP: Names vs. Numbers

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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html

Jul 19 '05 #1
4 2154
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" <nj********@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP11.phx.gbl...
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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html

Jul 19 '05 #2
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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html

"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:uQ**************@tk2msftngp13.phx.gbl...
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" <nj********@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP11.phx.gbl...
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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html


Jul 19 '05 #3
Populate an array and use the array indexes instead?

Chris.

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP11.phx.gbl...
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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html

"Ray at <%=sLocation%>" <ra*@ajf8jalskdfna.sefrhja7yasdf.com> wrote in
message news:uQ**************@tk2msftngp13.phx.gbl...
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" <nj********@hotmail.com> wrote in message
news:eQ**************@TK2MSFTNGP11.phx.gbl...
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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html



Jul 19 '05 #4
The FileSystemObject Files Collection has a .Count property that you can
use.

Mike Ober.

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP11.phx.gbl...
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
nj********@hotmail.com
http://www.students.kutztown.edu/soka0908/HomePage.html

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Berry | last post by:
Hi All. I'm trying to write an ASP page that shows me the UNIQUE account number for a customer (so I can pass it to another page) based on a search criteria. For example, I want to do a select...
5
by: Guest | last post by:
I'd appreciate some help from any architectural gurus out there.I'm creating a web app with 3 tiers, A presentation layer which is an aspnet application. A business object layer which is a...
0
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of...
0
by: guy | last post by:
vb2005 is there a way of assigning multiple collections to be the datasource for a grid? eg suppose i have a database with People and PhoneNumbers tables and a PeoplePhoneNumbers link table ...
11
by: CMM | last post by:
First let me say that maybe I'm having a "duh" moment and perhaps I'm missing something... but it seems to me that no one thing in the System.Collections namespace (even in .NET 2.0) even comes...
7
by: berkeleydb_user | last post by:
Guys I developed a small asp web service app in Visual Studio .NET. To deploy on another server, I just copied the whole dir as is from my c:\inetpub\wwwroot to the same dir on destination...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
2
by: Terry Olsen | last post by:
I have an array filled with counts of numbers. Example: ar(1) contains the number of occurrances of the number 1 ar(2) contains the number of occurrances of the number 2 etc... I need to find...
3
by: djcamo | last post by:
Hi, I have a situation where I have a collection that holds numbers. Mostly they are concurrent eg. 125801-125899 but sometimes they are not eg. 125801-125899, 195301-399. Is there any way to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.