这段代码最后部分怎么运行不了哦?
时间:2011-12-25
来源:互联网
Dim dc As New Dictionary
Dim arr() As String
Dim m As Integer
Sub SearchFile(MyPath As String)
m = 0
If MyPath = "" Then Exit Sub
Dim Myname As String, dir_i() As String, i As Long, idir As Long
If Right(MyPath, 1) <> "\" Then MyPath = MyPath + "\"
On Error Resume Next
Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem)
Do While Myname <> ""
DoEvents
If Myname <> "." And Myname <> ".." Then
If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目录
idir = idir + 1
ReDim Preserve dir_i(idir) As String
dir_i(idir - 1) = Myname
Else
If Myname Like "*xls" Or Myname Like "*xlsx" Then
ReDim Preserve arr(0 To m) As String
List1.AddItem MyPath & Myname '把找到的文件显示到列表框中
arr(m) = MyPath & Myname
' List1.AddItem arr(m)
m = m + 1
End If
End If
End If
Myname = Dir '搜索下一项
Loop
For i = 0 To idir - 1
Call SearchFile(MyPath + dir_i(i))
Next
ReDim dir_i(0) As String
End Sub
Private Sub Command1_Click()
Dim sh
Dim oFolder
Set sh = CreateObject("shell.application")
Set oFolder = sh.BrowseForFolder(Me.hWnd, "请选择文件夹", BIF_EDITBOX Or BIF_RETURNONLYFSDIRS Or BIF_NONEWFOLDERBUTTON)
'If Not oFolder Is Nothing Then
SearchFile oFolder.Self.Path
For i = 0 To UBound(arr)
List1.AddItem arr(m)
Next i
End Sub
Dim arr() As String
Dim m As Integer
Sub SearchFile(MyPath As String)
m = 0
If MyPath = "" Then Exit Sub
Dim Myname As String, dir_i() As String, i As Long, idir As Long
If Right(MyPath, 1) <> "\" Then MyPath = MyPath + "\"
On Error Resume Next
Myname = Dir(MyPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem)
Do While Myname <> ""
DoEvents
If Myname <> "." And Myname <> ".." Then
If (GetAttr(MyPath & Myname) And vbDirectory) = vbDirectory Then '如果找到的是目录
idir = idir + 1
ReDim Preserve dir_i(idir) As String
dir_i(idir - 1) = Myname
Else
If Myname Like "*xls" Or Myname Like "*xlsx" Then
ReDim Preserve arr(0 To m) As String
List1.AddItem MyPath & Myname '把找到的文件显示到列表框中
arr(m) = MyPath & Myname
' List1.AddItem arr(m)
m = m + 1
End If
End If
End If
Myname = Dir '搜索下一项
Loop
For i = 0 To idir - 1
Call SearchFile(MyPath + dir_i(i))
Next
ReDim dir_i(0) As String
End Sub
Private Sub Command1_Click()
Dim sh
Dim oFolder
Set sh = CreateObject("shell.application")
Set oFolder = sh.BrowseForFolder(Me.hWnd, "请选择文件夹", BIF_EDITBOX Or BIF_RETURNONLYFSDIRS Or BIF_NONEWFOLDERBUTTON)
'If Not oFolder Is Nothing Then
SearchFile oFolder.Self.Path
For i = 0 To UBound(arr)
List1.AddItem arr(m)
Next i
End Sub
作者: ah2042 发布时间: 2011-12-25
For i = 0 To UBound(arr)
List1.AddItem arr(m)
Next i
这句话错了。搞不明白,数组怎么会定义错呢?
List1.AddItem arr(m)
Next i
这句话错了。搞不明白,数组怎么会定义错呢?
作者: ah2042 发布时间: 2011-12-25
arr(m)?
m?
你要在这个循环里添加巨多次的arr(m)么?
m?
你要在这个循环里添加巨多次的arr(m)么?
作者: myjian 发布时间: 2011-12-25
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28