Link to home
Start Free TrialLog in
Avatar of keithturner
keithturnerFlag for Canada

asked on

legacy VB6 - readline not working for new text files - reads entire file instead

I am updating a legacy VB6 application that reads a text file line by line, and a different developer has updated the program that writes this text file, so now instead of reading one line, the legacy program reads the entire file. Theoretically we should be able to drop the files in the same program without changes, but this not recognizing line ends makes our simple legacy parser not work.

I checked and there is still a newline \n char written at the end of each line. I figure that he must be using a different encoding type or something where the readline does not recognize the end of the line in the new files - no problem with textpad and notepad putting in the new line though. The code fragment attached shows the readline used.

I tested with an older file, no problem, reads just one line fine, but a newer file created with the new app (which is simply a different version of Director with Flash embedded instead of pure director and no Flash) reads the whole file, which is bad as the VB6 program parses and uses each line before the next one is to be read.

The "lots of work" solution (some of which is political) is to have him write a stop char of some type at the end of each line, then split from there, hence not maxing points here at EE, but I'd like to know what is going on and solve it at my end if possible.

I've stripped out the personal data on a couple of files, an old one that works and a new one with just test info in it, and would appreciate any suggestions on how to tell what is going on.

(in sample ts is a textstream object)
Set ts = filPostData.OpenAsTextStream

' read the first line
    strData = ts.ReadLine

Open in new window

DataPost.txt
DataPost-good-but-old.txt
Avatar of HooKooDooKu
HooKooDooKu

I know that the old "classic" VB readline looked for either a Cr (Carriage Return) or CrLf (Carriage Return/Linefeed pair) to indicate the end of the line.

If the programmer is writing the lines outputing JUST a Lf (Line Feed) charactor, VB doesn't see that as an end-of-line marker.  
Avatar of keithturner

ASKER

Thanks, do you know of any way to test the two text files attached to see what is what?

I looked and both have line termination with "\n", but not sure how to check for the pair.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, I now see that you've posted some samples.

Your DataPost.txt has nothing in it to denote the end of a line, except the file ends with a Cr.

The DataPost-good-but-old.txt is filled with CrLf pairs denoting the end of each line.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, you used a hex editor to find the eol.

The intrinsic method works just fine for both the new and old files.

But I'll pass on the missing pair to the developer as that may be a better solution for him, hence the split points.

Once again thanks for your time and effort.