how to write a vb6 code to identify an "eof" char within a txt file (or ascii file)?

Posted on 2013-05-21
Last Modified: 2013-07-31
I have encountered an issues with a "funny" char in the middle of a text file that was created on a different server, and send to me via ftp.

the file contains an "eof" char in the middle of the line.
you can only use notepad to see it, and I can remove and save it.  

However, I can not use a program in vb6 to remove it.  because the vb6, will read one line at a time.  when it sees the 'eof'.  it think it is end of the file.  so I can not read the line complete.

attach is the text file. (the char is on the 7th char of the 2nd line.

do anyone know if there is a method I should use so I can write sample code to be able to read char by char, include be able to read the eof char.  so I can remove it and write back to the new file?

if you have a sample code that will be great.

Question by:mshox1
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
  • 6
  • 2
LVL 16

Expert Comment

ID: 39184701
Try switching the FTP transfer between ASCII and BINary modes as that may impact the EOL characters.

If that doesn't work, you can use Replace() and the special vbCrLf constant ...  vbCrLf evaluates to Asc(13) & Asc(10)
LVL 16

Expert Comment

ID: 39184743
I just looked at your sample file.  That appears to be a lonely vbLf character without the vbCr... so just Asc(10) by itself

for vb6 try syntax like:    row = Replace(row, Asc(10), "")
LVL 16

Expert Comment

ID: 39184754
.... but if that screws up the existing vbCrLf then you'll have to go back and replace the orphaned vbCr with vbCrLf
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 39184837
1. it is eof char.  not vbCR,   because if you use the following vb code to read the "row"

the return r_str will be first char of the line, up to the char right before the 'funny char'
and thing after that, you can read anymore....

2.  I forget the dos command that you can use the 'dump' the file into asc, or hex or ebcdic format.  if you do that, you can see that partical char is something high number of
asc(N),  n may be 256 or sometings.  by the way, if you tell me the dos command can use to dump the file in asc char set, or hex char set, this will help.

3. I am looking for a method can can read one char at a time (not 1 line at a time),
   and it will read include that char.

just want to clarify.  and appreciate your addtional input.


dim ch_read as integer
ch_read = freefile()
open "input.txt" for input as #ch_read

Line Input #ch_read, r_str
len_str = Len(r_str)
LVL 16

Expert Comment

ID: 39184853
The sample file has character 10 (eg: A0 in the hex editor) so I dunno...

You are probably thinking of the "dubug" program in dos... to use it type debug <filename> except put the real filename.  It doesn't seem to be installed on my computer so I looked at it with the HxD hex editor program downloaded from cnet.
LVL 16

Expert Comment

ID: 39184863
if you have "debug" on your computer then you'll see a funny prompt when it starts so mash the "d" character to display the first few bytes and then keep mashing it however many times you need to scroll down to the part of the file that you need to examine.
LVL 16

Accepted Solution

AlexPace earned 500 total points
ID: 39184884
I suppose if you really want to go character by character you could open it in Binary mode and then use Get() in a loop ... there are probably some good internet resources if you search on "vb6 read binary file" or somesuch.

Author Closing Comment

ID: 39371814
thank you.  I have resolved the issues by open the file with binary mode and be able to read char by char.  thank you

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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