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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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.…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

624 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