Powerbasic Museum 2020-B

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Scripting => Windows Script Host => Topic started by: José Roca on July 14, 2008, 10:48:03 PM

Title: IWshEnvironment.Count Method
Post by: José Roca on July 14, 2008, 10:48:03 PM


The following code illustrates the use of the Count method:


#INCLUDE "WSHOM.INC"

DIM pWsh AS IWshShell
DIM pWshEnv AS IWshEnvironment
DIM nCount AS LONG
DIM pUnk AS IUnknown
DIM pEnum AS IEnumVARIANT
DIM IID_IEnumVARIANT AS GUID
DIM i AS LONG
DIM celtFetched AS LONG
DIM vValue AS VARIANT

' Create an instance of Windows Script Host
pWsh = NEWCOM "WScript.Shell"
' Get a reference to environment collection
pWshEnv = pWsh.Environment
' Get the number of objects in the collection
nCount = pWshEnv.Count
' Get a reference to the collection's enumerator
pUnk = pWshEnv.NewEnum_
pEnum = pUnk
FOR i = 0 TO nCount - 1
   pEnum.Next 1, vValue, celtFetched
   IF celtFetched = 0 THEN EXIT FOR
   STDOUT VARIANT$(vValue)
NEXT