如何使用vb计数

来源:百度知道 编辑:UC知道 时间:2024/05/24 12:30:04
Option Explicit
On Error Resume Next
Dim folderpath
Dim objFSO
Dim objFolder
Dim colFiles
Dim objFile
FolderPath = "C:\Heroes3"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FolderPath)
Set colFiles= objFolder.Files
For Each objFile In colFiles
Wscript.Echo objFile.name
next
---------------------------------
我需要计算objfile.name的总数,应该怎么改?

记得 回答过的!
dim fileNo
fileNo=0
For Each objFile In colFiles
Wscript.Echo objFile.name
fileNo = fileNo + 1
next

Private Sub Form_click()
Dim folderpath
Dim objFSO
Dim objFolder
Dim colFiles
Dim objFile
Dim i As Integer
folderpath = "z:\1"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folderpath)
Set colFiles = objFolder.Files
For Each objFile In colFiles
i = i + 1
Debug.Print "第" & i & "个文件: " & objFile.Name
Next
End Sub

colFiles.Count