VB读取文件夹下文件到数组出错,请大侠帮忙看看,本人没多少分,解决后全送了

scudsoft 2007-12-19 06:45:59
'在pic文件夹下有若干个名为Sc***.Dps的文件,要将这些文件读入数组处理,得不到文件名,请帮忙看看
我分不高,解决后全送了

Dim FileName As String
Dim strFile() As String
Dim n As long,i As Long

FilePath = App.Path & "\Pic\"
FileName = Dir(FilePath & "Sc*.Dps")

n = o
If FileName <> "" Then
Do
DoEvents
n = n + 1
FileName = Dir()
Loop Until FileName = ""
End If

List1.Clear
Text1.Text = n '显示文件数(可以正常显示)

ReDim strFile(1 To n) As String
For i = 1 To n
strFile(i) = FileName '问题应该是出在这儿
i = i + 1
List1.AddItem strFile(i)

Next

End Sub
...全文
52 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
............................
回复
skyell 2007-12-22
好,呵呵
回复
我猜你是要实现这样的效果吧

Private Sub Command1_Click()
Dim FileName As String
Dim filepath As String
Dim strFile() As String
Dim n As Long
Dim i As Long

filepath = App.Path & "\Pic\"
FileName = Dir(filepath & "Sc*.Dps")

n = 0
While FileName <> ""
DoEvents
n = n + 1
ReDim Preserve strFile(n)
strFile(n) = FileName
FileName = Dir()
Wend

List1.Clear
Text1.Text = n

For i = 1 To n
List1.AddItem strFile(i)
Next
End Sub
回复
scudsoft 2007-12-19
多谢多谢,一天后才可以加分,明天给您加上哈
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告