展开全部
dim a as string
dim files() as string
dim filecount as integer
dim nwc as integer
const path=路径
a = dir(path)
do while a<>""
if right(a,4)=".txt" then
filecount=filecount+1
end if
a=dir
loop
redim files(1 to filecount)
a = dir(path)
do while a<>""
nwc=nwc+1
if right(a,4)=".txt" then
open a for input as #1
do until eof(1)
dim tmp as string
line input #1,tmp
files(nwc) = files(nwc) & vbcrlf & tmp
loop
close #1
end if
loop
'在吃方便面就懒得开VB了
dim files() as string
dim filecount as integer
dim nwc as integer
const path=路径
a = dir(path)
do while a<>""
if right(a,4)=".txt" then
filecount=filecount+1
end if
a=dir
loop
redim files(1 to filecount)
a = dir(path)
do while a<>""
nwc=nwc+1
if right(a,4)=".txt" then
open a for input as #1
do until eof(1)
dim tmp as string
line input #1,tmp
files(nwc) = files(nwc) & vbcrlf & tmp
loop
close #1
end if
loop
'在吃方便面就懒得开VB了
追问
调试显示ReDim files(1 To filecount) 下标越界 能不能再帮忙看下
追答
好的,等下我传代码上来啊
Dim A As String
Dim Files() As String
Dim FileCount As Integer
Dim Nwc As Long
Dim Path As String
Path = "c:\b\"
If Mid(Path, Len(Path)) "\" Then
'报错
Err.Raise 888, "啦啦啦了饿啊,路径错误", "啦啦啦了饿啊,路径要加\ ,不要不加!你可以把注释了的文字改出来,注释的文字是加\的,如果使用注释的代码话的,注释掉这句"
'Path = Path & "\"
End If
A = Dir(Path)
Do While A ""
If Right(A, 4) = ".txt" Then
FileCount = FileCount + 1
End If
A = Dir
Loop
ReDim Files(1 To FileCount)
A = Dir(Path)
Do While A ""
If Right(A, 4) = ".txt" Then
Nwc = Nwc + 1
Open Path & A For Input As #1
Do Until EOF(1)
Dim tmp As String
Line Input #1, tmp
Files(Nwc) = Files(Nwc) & vbCrLf & tmp
Loop
Close #1
End If
A = Dir
Loop
'代码写好了啊……这次不会错了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询