Solved

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

Posted on 2013-05-21
8
497 Views
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.

thanks
sample-file-with-eof.txt
0
Comment
Question by:mshox1
  • 6
  • 2
8 Comments
 
LVL 16

Expert Comment

by:AlexPace
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)
0
 
LVL 16

Expert Comment

by:AlexPace
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), "")
0
 
LVL 16

Expert Comment

by:AlexPace
ID: 39184754
.... but if that screws up the existing vbCrLf then you'll have to go back and replace the orphaned vbCr with vbCrLf
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:mshox1
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.

thanks



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)
0
 
LVL 16

Expert Comment

by:AlexPace
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.
0
 
LVL 16

Expert Comment

by:AlexPace
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.
0
 
LVL 16

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:mshox1
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
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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