vbscript打印实例值一个接一个

时间:2015-03-30 14:28:29

标签: arrays vbscript

这是我的代码:

`strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM MSFC_FCAdapterHBAAttributes")
For each objItem in colItems 
        Wscript.Echo "Active: " & objItem.Active(0)
Next`

我得到这样的输出:

`Active: True` <br/>
`Active: True`

但我需要获得输出:Active: True, True

有人可以帮我这个吗?

仅当SAN连接到服务器但您可以使用任何其他类时,此查询才有效。

-KAKA -

1 个答案:

答案 0 :(得分:0)

您可以创建一个变量来存储它们,使用 strActives

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSFC_FCAdapterHBAAttributes")
strActives = "" ' <-- Empty String here
For Each objItem In colItems
    If Len(strActives) > 0 Then strActives = strActives & ", " ' Append a comma if it is not empty
    strActives = strActives & objItem.Active(0) ' Append the value
Next
' Here only echo if the strActives is not empty
If Len(strActives) > 0 Then Wscript.Echo "Active: " & strActives