首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

这段代码最后部分如何运行不了哦

2012-02-03 
这段代码最后部分怎么运行不了哦?Dim dc As New DictionaryDim arr() As StringDim m As IntegerSub Searc

这段代码最后部分怎么运行不了哦?
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

[解决办法]
arr(m)?

m?

你要在这个循环里添加巨多次的arr(m)么?

[解决办法]
For i = 0 To UBound(arr)
List1.AddItem arr(i)
Next i

热点排行