Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 76

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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

705 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