VB 如何逐个打开一个文件夹里面的多个txt文件。 35
如1.txt,2.txt,3.txt,4.txt这四个txt文件。我打开1.txt进行读取后,关闭,再打开2.txt,如此进行。求代码帮助!...
如1.txt,2.txt,3.txt,4.txt这四个txt文件。我打开1.txt进行读取后,关闭,再打开2.txt,如此进行。求代码帮助!
展开
1个回答
2015-12-02
展开全部
Dim Files() As String
Private Sub Command1_Click()
getFiles "c:\", Files() '获得文件,文件保存在Files()中
'后面为读取数据
End Sub
Private Sub getFiles(ByVal FilePath As String, F() As String)
Dim FileList As FileListBox
Dim i As Integer
Set FileList = Me.Controls.Add("VB.FileListBox", "FileList", Me)
FileList.Pattern = "*.txt"
FileList.Path = FilePath
For i = 0 To FileList.ListCount - 1
ReDim Preserve F(i)
F(i) = FilePath & FileList.List(i)
Next
Me.Controls.Remove FileList.Name
Set FileList = Nothing
End Sub
Private Sub Command1_Click()
getFiles "c:\", Files() '获得文件,文件保存在Files()中
'后面为读取数据
End Sub
Private Sub getFiles(ByVal FilePath As String, F() As String)
Dim FileList As FileListBox
Dim i As Integer
Set FileList = Me.Controls.Add("VB.FileListBox", "FileList", Me)
FileList.Pattern = "*.txt"
FileList.Path = FilePath
For i = 0 To FileList.ListCount - 1
ReDim Preserve F(i)
F(i) = FilePath & FileList.List(i)
Next
Me.Controls.Remove FileList.Name
Set FileList = Nothing
End Sub
追问
追加我的问题,我将1.txt打开后,取出一个"OK",然后再打开下一个2.txt文件,取出一个字符串"OK"后,再打开3.txt,以此类推,求代码.谢谢啦
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询