Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
551 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

971 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