473,395 Members | 1,936 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,395 software developers and data experts.

How to handle Collections?

Hi,

I'm very new to PHP, and am toying with some COM samples... specifically
the Windows FileSystem object.

This object has a property Drives, which returns a collection of Drive
objects (one for each drive letter). How can I enumerate this collection?

Here's the very basics:

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo("$drives->Count Drives");

This much works correctly (I get "4 Drives").

The next logical thing I'd like to do is something like:

foreach($drives as $drive)
{
echo $drive->VolumeName;
}

....however, I don't get the expected results. If I add a diagnostic
echo, it get's fired once (rather than 4 times) and the existing echo
neither returns anything or any error.

Thoughts?

Is this a syntax thing, or a fundamental "PHP isn't VB mate"
misunderstanding on my part? ;)

Ta,
Jon

Jul 17 '05 #1
4 3980
On Wed, 07 Jan 2004 16:00:35 +0000, Jon Grieve wrote:
Hi,

I'm very new to PHP, and am toying with some COM samples... specifically
the Windows FileSystem object.

This object has a property Drives, which returns a collection of Drive
objects (one for each drive letter). How can I enumerate this collection?

Here's the very basics:

$fs = new COM("Scripting.FileSystemObject"); $drives = $fs->Drives;
echo("$drives->Count Drives");

This much works correctly (I get "4 Drives").

The next logical thing I'd like to do is something like:

foreach($drives as $drive)
{
echo $drive->VolumeName;
}
}
...however, I don't get the expected results. If I add a diagnostic echo,
it get's fired once (rather than 4 times) and the existing echo neither
returns anything or any error.

Thoughts?

Is this a syntax thing, or a fundamental "PHP isn't VB mate"
misunderstanding on my part? ;)

Ta,
Jon

Hi Jon,

Have you tried:
var_dump($drives);die;
for debugging? This should outline the exact contents and type of
$drives.. maybe there's an issue in the storage method (I've not tried
personally, so just guessing =) ).

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.

Jul 17 '05 #2
Yup, PHP isn't VB. You have to call methods of IEnumVariant to enumerate
through a collection.

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo $drives->Count;
$drives->Reset();
while($drive = $drives->Next()) {
echo $drive->VolumeName;
}

If you need to use COM, stick with VB. COM support in PHP isn't terribly
stable.

Uzytkownik "Jon Grieve" <jgrieve@southdown-co-uk> napisal w wiadomosci
news:vv************@corp.supernews.com...
Hi,

I'm very new to PHP, and am toying with some COM samples... specifically
the Windows FileSystem object.

This object has a property Drives, which returns a collection of Drive
objects (one for each drive letter). How can I enumerate this collection?

Here's the very basics:

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo("$drives->Count Drives");

This much works correctly (I get "4 Drives").

The next logical thing I'd like to do is something like:

foreach($drives as $drive)
{
echo $drive->VolumeName;
}

...however, I don't get the expected results. If I add a diagnostic
echo, it get's fired once (rather than 4 times) and the existing echo
neither returns anything or any error.

Thoughts?

Is this a syntax thing, or a fundamental "PHP isn't VB mate"
misunderstanding on my part? ;)

Ta,
Jon

Jul 17 '05 #3
Chung,

Thanks -- that works fine. That certainly wasn't obvious to me at
all... the Next() and Reset() functions seem to be built-in Array functions?

Jon

Chung Leong wrote:
Yup, PHP isn't VB. You have to call methods of IEnumVariant to enumerate
through a collection.

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo $drives->Count;
$drives->Reset();
while($drive = $drives->Next()) {
echo $drive->VolumeName;
}

If you need to use COM, stick with VB. COM support in PHP isn't terribly
stable.

Uzytkownik "Jon Grieve" <jgrieve@southdown-co-uk> napisal w wiadomosci
news:vv************@corp.supernews.com...
Hi,

I'm very new to PHP, and am toying with some COM samples... specifically
the Windows FileSystem object.

This object has a property Drives, which returns a collection of Drive
objects (one for each drive letter). How can I enumerate this collection?

Here's the very basics:

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo("$drives->Count Drives");

This much works correctly (I get "4 Drives").

The next logical thing I'd like to do is something like:

foreach($drives as $drive)
{
echo $drive->VolumeName;
}

...however, I don't get the expected results. If I add a diagnostic
echo, it get's fired once (rather than 4 times) and the existing echo
neither returns anything or any error.

Thoughts?

Is this a syntax thing, or a fundamental "PHP isn't VB mate"
misunderstanding on my part? ;)

Ta,
Jon



Jul 17 '05 #4
COM support is not integrated into PHP as it's in VB. Next and Reset are
methods of the IEnumVariant interface, which is provided by the COM
collection object.

Uzytkownik "Jon Grieve" <jgrieve@southdown-co-uk> napisal w wiadomosci
news:vv************@corp.supernews.com...
Chung,

Thanks -- that works fine. That certainly wasn't obvious to me at
all... the Next() and Reset() functions seem to be built-in Array functions?
Jon

Chung Leong wrote:
Yup, PHP isn't VB. You have to call methods of IEnumVariant to enumerate
through a collection.

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo $drives->Count;
$drives->Reset();
while($drive = $drives->Next()) {
echo $drive->VolumeName;
}

If you need to use COM, stick with VB. COM support in PHP isn't terribly
stable.

Uzytkownik "Jon Grieve" <jgrieve@southdown-co-uk> napisal w wiadomosci
news:vv************@corp.supernews.com...
Hi,

I'm very new to PHP, and am toying with some COM samples... specifically
the Windows FileSystem object.

This object has a property Drives, which returns a collection of Drive
objects (one for each drive letter). How can I enumerate this collection?
Here's the very basics:

$fs = new COM("Scripting.FileSystemObject");
$drives = $fs->Drives;
echo("$drives->Count Drives");

This much works correctly (I get "4 Drives").

The next logical thing I'd like to do is something like:

foreach($drives as $drive)
{
echo $drive->VolumeName;
}

...however, I don't get the expected results. If I add a diagnostic
echo, it get's fired once (rather than 4 times) and the existing echo
neither returns anything or any error.

Thoughts?

Is this a syntax thing, or a fundamental "PHP isn't VB mate"
misunderstanding on my part? ;)

Ta,
Jon


Jul 17 '05 #5

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

Similar topics

13
by: DraguVaso | last post by:
Hi, I have a Generic List, for instance: Public MyPersonnesDeContact As New System.Collections.Generic.List(Of clsPersonne) My clsPersonne raises some events, and I want to be able to handle...
6
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
0
by: Marc Bartsch | last post by:
Hi, I have a WinForms application (C#, VS 2005) that consists of a treeview control and a notify icon. Below is a complete example of this application. The treeview has one root node and one child...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.