Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextStream object problem--AtEndofStream

Status
Not open for further replies.

PTW

Programmer
Jul 7, 2000
82
CA
Hi there!

Don't know if I'm just having a brain lock-up or if there's something wrong with TextStreamObject.AtEndOfLine

For the purposes of teaching myself the FileSystemObject, I'm just simply copying one file to another, line-by-line. However, it copies everything except the last line. Here's a code snippet:


Set fso = New FileSystemObject
Set OrigFile = fso_OpenTextFile(strFileName, ForReading, False)
Set NewFile = fso.CreateTextFile(strFileName2, True)

Do While OrigFile.AtEndOfStream <> True
NewFile.WriteLine (OrigFile.ReadLine)
OrigFile.SkipLine
Loop


It looks like when I SKIPLINE to the last line, AtEndOfStream = True and the code never gets a chabxce to copy the last line. Any recomendations on how to avoid that problem? Thanks!



PTW
 
Yes it is going to exit out as soon as origfile.atendofstream = true

You could try
Do Until origfile.atendofstream = true

Craig, mailto:sander@cogeco.ca
&quot;Procrastination is the art of keeping up with yesterday.&quot;
I hope my post was helpful!!!
 
You should not use the Skipline method. Just use the following:

Do While OrigFile.AtEndOfStream <> True
NewFile.WriteLine (OrigFile.ReadLine)
Loop

The readline method advances to the next line by itself, using the skipline will only read every other line. Hope this helps. Anything is possible, the problem is I only have one lifetime.[thumbsup2]
 
Aha! Thx foada...that was the answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top