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

Posted on 2010-01-11
Medium Priority
Last Modified: 2013-11-26
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

Question by:keithturner
  • 3
  • 2
LVL 16

Expert Comment

ID: 26286190
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.  

Author Comment

ID: 26286224
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.
LVL 77

Accepted Solution

GrahamSkan earned 360 total points
ID: 26286225
You could try the intrinsic file reading code.
Sub ReadFile()
    Dim f As Integer
    Dim strData As String
    f = FreeFile
    Open "C:\MyFolder\MyFile.txt" For Input As #f
        Do Until EOF(f)
            Line Input #f, strData
            MsgBox strData
    Close #f
End Sub

Open in new window

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

LVL 16

Expert Comment

ID: 26286265
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.
LVL 16

Assisted Solution

HooKooDooKu earned 140 total points
ID: 26286317
I've downloaded both samples.  I'm looking at DataPost.txt with a hex editor, and there is NOTHING in the file to denote the end of a line.

Looking at the other file and I can see that lines should be ending after "type=eval|" and "type=quiz|".  But there is no sort of end of line marker after these pieces of text in the DataPost.txt file.

Author Closing Comment

ID: 31675662
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.

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question