Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange File Character annoying problem

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I am trying to read a text file that contains the data read from a device connected to a modem.
Occasionally if there is corruption you get odd characters in the file mixed up with the regular text.
Eg "Hello?there" where the space between the two words is chr(26) instead of chr(32).
Character 26 creates a problem when handing the text file later.
If I use "Input#" or "Line Input#" in a loop, the read stops where the chr(26)is
It thinks an EOF has been detected.

How can I continue to read past Chr(26)? The whole file reads normally using notepad with a little box where chr(26) is.

A test file can be made with
Print #1,"Hello" & chr(26) & "there";
 
I haven't touched VB in years but I assume you are doing this:


Open "TESTFILE" For Input As #1
' do whatever
Close #1


Try this instead:
Open "TESTFILE" For Binary Access Read As #1

'do whatever
Close #1

I recall doing something like this about 5 years ago

Good luck
 
Ctrl-Z is the text file EOF character.

I think the only workaround is binary I/O or Input$().

This is because [tt]Input #[/tt] and [tt]Line Input #[/tt] process the text stream looking for "text file delimiters" such as commas, Cr or CrLf, quotes, leading spaces to trim, etc. The Ctrl-Z EOF is treated as such a text delimiter.

You could also use FSO I/O which is another form of text file I/O that is blind to most of those delimiters. It only looks for CrLf line delimiters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top