51Testing软件测试论坛

标题: 请教各位前辈VBS中drives集合的count属性和ITEM属性的实际应用 [打印本页]

作者: SUPERWOMEN    时间: 2009-6-30 18:38
标题: 请教各位前辈VBS中drives集合的count属性和ITEM属性的实际应用
想请问各位前辈drives集合的count属性和ITEM属性的实际应用。麻烦看下下面函数:
Function ShowDriveList()
    Dim fso, d, dc, s, n
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dc = fso.Drives
   msgbox dc.count
    For Each d in dc
     n = ""
   s = s & d.DriveLetter & " - "
        If d.DriveType = Remote Then
            n = d.ShareName
        ElseIf d.IsReady Then
            n = d.VolumeName
        End If
        s = s & n &"<BR>"
    Next
   ShowDriveList = s
End Function
call ShowDriveList()
msgbox ShowDriveList
1)我的电脑上有4个盘,执行时msgbox dc.count,弹出两次对话框,都显示的是4,请教前辈们为什么会出现两次?
2)ITEM属性在我这段代码中怎么应用?
请大侠们给指点下。谢谢。
作者: fei.ge    时间: 2009-6-30 19:23
这是QTP帮助文档上的内容.

1)我的电脑上有4个盘,执行时msgbox dc.count,弹出两次对话框,都显示的是4,请教前辈们为什么会出现两次?
<<<因为你call ShowDriveList()加msgbox ShowDriveList,一共运行了2次函数

2)ITEM属性在我这段代码中怎么应用?
<<<有item属性吗....?期待..

[ 本帖最后由 fei.ge 于 2009-6-30 19:30 编辑 ]
作者: onlonely    时间: 2009-7-1 08:51
标题: 回复 2# 的帖子
你看你后面的调用..
call ShowDriveList()
msgbox ShowDriveList
这样,的语句会执行2次函数的.
call代表执行一次,
msgbox ShowDriveList
会先执行ShowDriveList然后结果用msgbox输出来
作者: hsjzfling    时间: 2009-7-1 09:58
msgbox dc.Item("C:").VolumeName
作者: SUPERWOMEN    时间: 2009-7-1 13:37
感谢各位前辈的指点,我把call ShowDriveList()这句删了就好了。

请问楼上的前辈,msgbox dc.Item("C:").VolumeName 这句应该放到那个位置,我执行了下,弹出框中没有任何内容,不知道这句话放的地方对不?
另:
msgbox dc.Item("C:").VolumeName中"C:"可以用于变量表示么?
还请前辈给与详细指点。
谢谢。
作者: SUPERWOMEN    时间: 2009-7-1 13:54
感谢楼上这位前辈的思路。
我前辈的思路加到代码中,最终终于调试通过了。供大家参考。如有不对地方,请大家都得指点。
Function ShowDriveList()
    Dim fso, d, dc, s, n
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set dc = fso.Drives
    msgbox dc.count
    For Each d in dc
     n = ""
   s = s & d.DriveLetter & " - "
        If d.DriveType = Remote Then
            n = d.ShareName
        ElseIf d.IsReady Then
            n = d.VolumeName
        End If
        s = s & n &"<BR>"
        If d.IsReady Then
       msgbox d.DriveLetter&"可用空间"&dc.Item(d.DriveLetter).FreeSpace       Else
        msgbox d.DriveLetter&"驱动器未就绪"
       End If   
    Next
   ShowDriveList = s
End Function
msgbox ShowDriveList




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2