本帖最后由 sky3785 于 2010-12-20 11:17:23 编辑

解决方案 »

  1.   

    Len(sDir)返回的是数值啊,能作为条件吗?
      

  2.   

    0一般代表false,即不满足循环条件。Do While 0
        Debug.Print “0”:Exit Do
    Loop
    Do While 1
        Debug.Print “1”:Exit Do
    Loop
      

  3.   

    Len(sDir)
    长度为0时停止循环。
      

  4.   

    0可以做为false,所有非0值可以做为true
      

  5.   


    Dim sPath$, sDir$, sFiles$(), iFiles&
    Private Sub Command1_Click()
       sPath = "c:\test\"
       If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
       iFiles = 0
       sDir = Dir(sPath & "*", vbDirectory)
       List1.Clear: List1.Visible = False
       While sDir <> vbNullString '或  While Len(sDir) <> 0  可以做为条件的
          If UCase(Right(sDir, 3)) = "XLS" Then
             ReDim Preserve sFiles(iFiles)
             sFiles(iFiles) = sPath & sDir
             List1.AddItem sFiles(iFiles)
             iFiles = iFiles + 1
          End If
          sDir = Dir()
       Wend
       List1.Visible = True
       MsgBox "搜索完成! 共搜索到 " & CStr(List1.ListCount) & " 个文件"
    End Sub