Re: How to handle Collections?
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@southd own-co-uk> napisal w wiadomosci
news:vvqhbnpovl lu58@corp.super news.com...[color=blue]
> 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[/color]
functions?[color=blue]
>
> Jon
>
>
>
>
>
> Chung Leong wrote:[color=green]
> > Yup, PHP isn't VB. You have to call methods of IEnumVariant to enumerate
> > through a collection.
> >
> > $fs = new COM("Scripting. FileSystemObjec t");
> > $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@southd own-co-uk> napisal w wiadomosci
> > news:vvob7l8dqq 72b1@corp.super news.com...
> >[color=darkred]
> >>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[/color][/color][/color]
collection?[color=blue][color=green][color=darkred]
> >>
> >>Here's the very basics:
> >>
> >> $fs = new COM("Scripting. FileSystemObjec t");
> >> $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"
> >>misunderstand ing on my part? ;)
> >>
> >>Ta,
> >>Jon
> >>[/color]
> >
> >
> >[/color]
>[/color]
How to handle Collections?
Collapse
This topic is closed.
X
X
-
Guest replied -
Guest repliedRe: How to handle Collections?
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:[color=blue]
> Yup, PHP isn't VB. You have to call methods of IEnumVariant to enumerate
> through a collection.
>
> $fs = new COM("Scripting. FileSystemObjec t");
> $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@southd own-co-uk> napisal w wiadomosci
> news:vvob7l8dqq 72b1@corp.super news.com...
>[color=green]
>>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. FileSystemObjec t");
>> $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"
>>misunderstand ing on my part? ;)
>>
>>Ta,
>>Jon
>>[/color]
>
>
>[/color]
Leave a comment:
-
Guest repliedRe: How to handle Collections?
Yup, PHP isn't VB. You have to call methods of IEnumVariant to enumerate
through a collection.
$fs = new COM("Scripting. FileSystemObjec t");
$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@southd own-co-uk> napisal w wiadomosci
news:vvob7l8dqq 72b1@corp.super news.com...[color=blue]
> 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. FileSystemObjec t");
> $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"
> misunderstandin g on my part? ;)
>
> Ta,
> Jon
>[/color]
Leave a comment:
-
Guest repliedRe: How to handle Collections?
On Wed, 07 Jan 2004 16:00:35 +0000, Jon Grieve wrote:
[color=blue]
> 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. FileSystemObjec t"); $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"
> misunderstandin g on my part? ;)
>
> Ta,
> Jon[/color]
Hi Jon,
Have you tried:
var_dump($drive s);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.ne t | forum.digiserv. net
Programming, Web design, development & hosting.
Leave a comment:
-
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. FileSystemObjec t");
$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"
misunderstandin g on my part? ;)
Ta,
Jon
Tags: None
Leave a comment: