开发者

How to read one line of text at a time and write back out to another file in VB6

I'm trying to read from file "A" one line at a time, make changes to that line, and write it back out to file "B". Append开发者_如何学运维ing File "B" as I go. I've found plenty of info on the web but none of it matches what I'm looking for.

Any ideas on how to implement this?


I threw this together real quick, but it should be pretty easy to read. You open your file to read, and your file to write to, and iterate through it.

Dim fileIn As Integer
Dim fileOut As Integer
Dim sLine As String

fileIn = FreeFile

Open "C:\Temp\input.txt" For Input As fileIn

fileOut = FreeFile

Open "C:\Temp\output.txt" For Append As fileOut

Do While Not EOF(fileIn)
    Line Input #fileIn, sLine
    sLine = sLine & " has been changed"  ' This is where you'd make your changes
    Print #fileOut, sLine
Loop

Close fileIn
Close fileOut
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜