回复 2楼 xzlxzlxzl
我回去修改一下之后发现依然只能读取到一行的数据
为了方便各位查错,我将所有代码发上来
程序代码:
Dim UnchangedData() As String, ChangedData() As String
Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
MsgBox "参数不完全。", vbCritical '检查参数完整性
Exit Sub
End If
If Text5.Text = "未开始转换" Then
Text5.Text = "" '清空日志
End If
Text5.Text = Text5.Text & vbCrLf & Now & "读取“" & Text1.Text & "”内的数据" '输出日志
'-----------------------
Dim LenTmp As Integer, FreeNumber As Integer
ReDim UnchangedData(1 To 65565) '重定义需要的变量
ReDim ChangedData(1 To 65565)
FreeNumber = FreeFile
Open Text1.Text For Input As #FreeNumber
DoEvents
While Not EOF(FreeNumber)
i = i + 1
Line Input #FreeNumber, UnchangedData(i)
DoEvents
Wend
Close #FreeNumber
LenTmp = i'标记读取到了多少行
Text5.Text = Text5.Text & vbCrLf & Now & "读取到" & LenTmp & "行的数据" '输出日志
'-------------------------
Text5.Text = Text5.Text & vbCrLf & Now & "开始替换" '输出日志
DoEvents
For i = 1 To LenTmp
ChangedData(i) = Replace(UnchangedData(i), Text2.Text, Text3.Text)
DoEvents
Next i
Text5.Text = Text5.Text & vbCrLf & Now & "替换完毕" '输出日志
Text5.Text = Text5.Text & vbCrLf & Now & "开始输出到“" & Text4.Text & "”文件" '输出日志
DoEvents
For i = 1 To LenTmp
Open (Text4.Text) For Append As #1 '以追加方式打开文件
Print #1, ChangedData(i) '在文件尾接着写入内容
Close #1
Next i
DoEvents
Close #1
Text5.Text = Text5.Text & vbCrLf & Now & "输出文件完毕" '输出日志
End Sub
我是想做一个小程序,可以读取文件,将这个文件里的关键字用Replace更改为另外的字符,但是每次都显示只能读取到一行(我自己在代码里加入了查错模块)
[此贴子已经被作者于2017-1-2 11:39编辑过]