Re: Alternative to FOR EACH
From: Viatcheslav V. Vassiliev (msnewsgroup_at_www-sharp.com)
Date: 04/16/04
- Next message: Richard Hall: "Window open / close vbscripting question"
- Previous message: Viatcheslav V. Vassiliev: "Re: error '80041010' using WMI SNMP in an ASP page."
- In reply to: J. van Heerde: "Alternative to FOR EACH"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 16 Apr 2004 22:43:37 +0400
Look documentation for your programming language or at least write what is
this language. For example, JScript uses Enumerator object for this purpose
(this object most probable will not be available from your language if it is
not JScript):
function ShowDriveList(){
var fso, s, n, e, x; //Declare variables.
fso = new ActiveXObject("Scripting.FileSystemObject");
e = new Enumerator(fso.Drives); //Create Enumerator on Drives.
s = "";
for (;!e.atEnd();e.moveNext()) //Enumerate drives collection.
{
x = e.item();
s = s + x.DriveLetter;
s += " - ";
if (x.DriveType == 3) //See if network drive.
n = x.ShareName; //Get share name
else if (x.IsReady) //See if drive is ready.
n = x.VolumeName; //Get volume name.
else
n = "[Drive not ready]";
s += n + "<br>";
}
return(s); //Return active drive list.
}
//------------------------------------
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE
"J. van Heerde" <Han@b-v-h.demon.nl> ???????/???????? ? ???????? ?????????:
news:jkqv70dar7kdp2pq2n6ll1k9th9ijkgjld@4ax.com...
> Hi Scripting Guys,
>
> I've been reading a lot of information on VBScript, WMI, WSH, but
> can't find a solution to my problem.. I'm not only using all examples
> for VBScript, but also for another programming language. In the
> Windows 2000 Scripting Guide I came across the following example:
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set colDrives = objFSO.Drives
> For Each objDrive in colDrives
> Wscript.Echo "Drive letter: " & objDrive.DriveLetter
> Next
>
> This works fine in VBScript.
>
> I have one big problem. The programming language I use doesn't support
> the FOR EACH .... IN .... command. With other examples I've always
> managed to use the .Count property to set up a FOR ... TO .... command
> in combination with the .Item() method. I've been digging the
> Internet, but can't find any method for solving my problem.
>
> How do I reference one specific object in the Drives collection in the
> FileSystemObject by index number?
>
> The following command does work, but is of no use, because it presumes
> I already know the drive letter.
>
> Wscript.Echo "Drive letter: " & objDrive.Item( "a:" ).DriveLetter
>
> The following code simply doesn't work.....
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set colDrives = objFSO.Drives
> For counter = 1 TO colDrives.Count
> Wscript.Echo "Drive letter: " & colDrives.Item( counter ).DriveLetter
> Next
>
> I also tried using the dictionary object, but didn't know how to
> transfer this collection to a dictionary collection.......(again by
> NOT using the FOR EACH command).
>
> Can anybody help?
>
> Kind regards,
> Han
- Next message: Richard Hall: "Window open / close vbscripting question"
- Previous message: Viatcheslav V. Vassiliev: "Re: error '80041010' using WMI SNMP in an ASP page."
- In reply to: J. van Heerde: "Alternative to FOR EACH"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|