Link to home
Start Free TrialLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Accessing collection element.

Hi there,

***********************
        Dim fso As Object
        Dim fld As Object
        Dim subfs As Object
        Dim subf As Object
       
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fld = fso.GetFolder(path)
        Set subfs = fld.SubFolders
        Set subf = subfs.Item(2)
***********************

I get an error on the last line, "Invalid procedure call or argument"...
ASKER CERTIFIED SOLUTION
Avatar of Nightman
Nightman
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Unimatrix_001

ASKER

What I'm after is getting hold of the last folder in that collection, is there a tidy way to do it without a for loop?
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Without knowing the key name, not that I know of.

I agree with you, it seems kind of dumb that you can't get it by index and having to know the key name to reference the object (why else would you be iterationg through in the first place, if not to get the name!).
angelIII: Could you expand on that please, are those methods I can use etc... ?
"Without knowing the key name, not that I know of."
Hmm, okay. Although yes, seems incredibly silly not getting an element by index!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mrdany: Thanks, although what I'm after is:

"is there a tidy way to do it without a for loop?"

Although, I'll wait for AngelIII to reply, and then I'll probably split the points. :)
>"is there a tidy way to do it without a for loop?"
no.
sorry unimatrix, i didnt read the comments.. i just read the main question and answered...
my bad!!
Hrm, okay... Thanks any everybody for your contributions. Points split. :)
mrdany: Np mate. ;)