![]() |
#2
linta12017-11-21 22:36
|
程序如下(红色部分就是最耗时间位置):
Private Sub Command4_Click()
Dim MyStr1() As String
Dim MyStr2() As String
Dim ttemp As String
Dim n As Long 'Integer
tt = Timer
'读取文档1到数组MyStr1里
n = 0
Open (Dir4.Path & "\" & File4.FileName) For Input As #1 '以读的方式打开文件
Do While Not EOF(1) ' 循环至文件尾
n = n + 1
ReDim Preserve MyStr1(n)
Line Input #1, MyStr1(n) '读入一行
Loop
Close #1 ' 关闭文件。
'读取文档2到数组MyStr2里
n = 0
Open (Dir5.Path & "\" & File5.FileName) For Input As #1 '以读的方式打开文件
Do While Not EOF(1) ' 循环至文件尾
n = n + 1
ReDim Preserve MyStr2(n)
Line Input #1, MyStr2(n) '读入一行
Loop
Close #1 ' 关闭文件。
'按照要求把数组里的内容组合到字符串变量
Dim MyStr As String
Dim i As Long
MyStr = ""
For i = 1 To UBound(MyStr1)
MyStr = MyStr & Left(MyStr1(i), 45) & MyStr2(i) & Mid(MyStr1(i), 56) & vbCrLf
Label1.Caption = "已完成" & i & "行" '加个label显示进度
DoEvents '行太多了,防止程序假死
Next i
'写新建文档文件
Open (Dir5.Path & "\新文档.txt") For Output As #1 '以输出方式打开文件
Print #1, MyStr
Close #1 ' 关闭文件。
tt = Timer - tt
MsgBox "ok" & vbCrLf & tt
End Sub
附 1.txt 2.txt 目标文件.txt
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录