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
468 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now