Re: Alternative to FOR EACH

From: Viatcheslav V. Vassiliev (msnewsgroup_at_www-sharp.com)
Date: 04/16/04


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



Relevant Pages

  • Re: JS 1.7 support: Who has it, etc.?
    ... always part of the MSHTML DOM API. ... JScript 5.0, and the MSDN Library documentation clearly distinguishes ... it is useful for everyday programming as new *language features* ... No, I am talking about the *programming language*, JScript. ...
    (comp.lang.javascript)
  • Re: print - portrait or landscape
    ... really be using JScript. ... The programming language really does not ... public function get Landscape: Boolean; ... public function set Landscape(Boolean); ...
    (comp.lang.javascript)
  • Re: Creating tables alternating with text in Word using JScript
    ... This is the only line in all of your code that is specific to jscript. ... to/receiving from the COM object to account for the programming language ... This email account is my spam trap so I ...
    (microsoft.public.scripting.jscript)
  • Re: accesing a database through odbc
    ... I'm new using Jscript. ... I'm customizing some fields in microsoft CRM, ... programming language. ...
    (microsoft.public.scripting.jscript)
  • Re: Mac:Need to hire a programmer.Preliminary questions
    ... I do this on a daily basis at my job, although it is VBScript to ... Any programming language can do that, ... > It depends on what language you decide to convert your script into. ...
    (comp.sys.mac.programmer.misc)