Click to See Complete Forum and Search --> : ReadLine


BMLekki
June 14th, 2001, 10:48 AM
I need to read one line of a txt and then store it to a string. Then take that string and use it to build a different file. Once that is finished it needs to go back and read line two.
Any ideas?

This is what I'm working with.



Dim FSys as new FileSystemObject

Dim strAddress as string
Dim strSubject as string
Dim strBody as string


private Sub Form_Load()
Call ReadFiles
End Sub


private Sub genEmail()

Dim OutStream as TextStream
outEmail = App.Path & "\outEmail.txt"
set OutStream = FSys.CreateTextFile(outEmail, true, false)
OutStream.WriteLine "..h1 " & strAddress
OutStream.WriteLine "..h2 " & strSubject
OutStream.WriteLine "..h3 " & strBody
OutStream.WriteLine "..h4 SEND"
set OutStream = nothing
End
End Sub


private Sub ReadFiles()
Dim InStream as TextStream

BodyText = App.Path & "\body.txt"
set InStream = FSys.OpenTextFile(BodyText, 1, false, false)
While InStream.AtEndOfStream = false
TLine = InStream.ReadLine
strSubject = strSubject & TLine & vbCrLf
TLine = InStream.ReadAll
strBody = strBody & TLine & vbCrLf
Wend
' Text1.Text = strBody
set InStream = nothing

Call GetAddress

End Sub


private Sub GetAddress()
Dim AddressInStream as TextStream

AddressText = App.Path & "\email.txt"
set AddressInStream = FSys.OpenTextFile(AddressText, 1, false, false)
While AddressInStream.AtEndOfStream = false
TLine = AddressInStream.ReadLine
'strAddress = strAddress & TLine & vbCrLf
strAddress = TLine & vbCrLf
Wend
'Text1.Text = strAddress & strBody
'Text1.Text = strAddress & strBody
set AddressInStream = nothing

Call genEmail

End Sub

ecannizzo
June 14th, 2001, 03:47 PM
What I see you doing is going through a loop and reading a line of text, then after the loop is done you call a sub to write the last line of text you read. The way you did it yesterday, you called the sub to write all the text read. I don't really understand what the problem is. If you want to write the line to the text file every time you read it, then you have to call the sub in the while loop.

Erica

Tower
June 14th, 2001, 08:00 PM
Maybe you can use static variable for save information about current line.
Before read line use

For i = 1 to CurrentLine
FSys.SkipLine
Next i

This code skiped needed amount of line.
After read increase variable CurrentLine