For Each...Next

上一篇 / 下一篇  2010-03-22 20:17:05 / 个人分类:VBScript

例子CollectionOfDrives.vbs

Option Explicit
On Error Resume Next
Dim colDrives 'the collection that comes from WMI
Dim drive   'an individual drive in the collection
Const DriveType = 3 'Local drives. From the SDK

set colDrives =_
GetObject("winmgmts:").ExecQuery("select size,freespace " &_
"from Win32_LogicalDisk where DriveType =" & DriveType)

For Each drive in colDrives 'walks through the collection
WScript.Echo "Drive: " & drive.DeviceID
WScript.Echo "Size: " & drive.size
WScript.Echo "Freespace: " & drive.freespace
Next

 

For Each...Next,描述的是个体和集合的概念,只要存在集合的概念,应第一考虑For Each...Next的用法,例如

files, and folders are returned as a collection from the fileSystemObject

 

 

From
Microsoft® VBScript. Step by Step
By Ed Wilson

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar