Removing trailing hex 1a (decimal 26)

B

Brad

I have an text file that I export which is then imported into the host
system of my client. The client concatenates the file with other
files. Access seems to be adding a trailing hex 1a (decimal 26) to
the end of the file. This is a big problem because no more data is
processed after our file because of this trailing character. Anybody
have any idea why this is happening or how to fix this problem?
 
S

Stuart McCall

Brad said:
I have an text file that I export which is then imported into the host
system of my client. The client concatenates the file with other
files. Access seems to be adding a trailing hex 1a (decimal 26) to
the end of the file. This is a big problem because no more data is
processed after our file because of this trailing character. Anybody
have any idea why this is happening or how to fix this problem?

The easiest way to fix this is to first generate the file, then
'post-process' it to remove the offending character. You can use VBA's
buit-in file handling commands to achieve this.

Dim intF As Integer
Dim strBuffer As String
Dim strFilePath As String

strFilePath = "C:\Temp\MyFile.txt"
intF = FreeFile

Open strFilePath For Binary Access Read As intF
strBuffer = Space$(LOF(intF))

'Grab the whole file
Get #intF, , strBuffer

'If bad char exists, remove it
If InstrRev(strBuffer, Chr(26)) = 1 Then
strBuffer = Left$(strBuffer, Len(strBuffer) - 1)
Close intF

'Delete the original file
Kill strFilePath

'and re-write it with 1 char less
Open strFilePath For Binary Access Write As intF
Put #intF, , strBuffer
End If
Close intF

Then send the modified file to your client.

(the above is untested 'air code')
 
S

Stefan Hoffmann

hi Brad,
I have an text file that I export which is then imported into the host
system of my client.
How do you export this text file?
Access seems to be adding a trailing hex 1a (decimal 26) to
the end of the file.
What are you doing exactly?


mfG
--> stefan <--
 
A

Albert D. Kallal

Brad said:
I have an text file that I export which is then imported into the host
system of my client. The client concatenates the file with other
files. Access seems to be adding a trailing hex 1a (decimal 26) to
the end of the file. This is a big problem because no more data is
processed after our file because of this trailing character. Anybody
have any idea why this is happening or how to fix this problem?

Correct. Since day one of the cp/m days the standard for terminating text
files insert a ctrl-z

If you are the dos prompt, you can copy your keyboard input to a text file
like:

copy con: t.txt

one
two
three ^z

So, if you type "one", then enter, "two" then enter and then three and then
ctrl-z key, you see the above state

1 files(s) copied.

Turns out that DOS actually did (and does) store the exact length of a text
file, but cp/m operating system, and several others could only store disk
sectors (usually 128 bytes). So, the ONLY way to know the actual end of file
was to place a ctrl-z at the end of a text type of file.

DOS which started out in 1980??? while not dependent on the ctrl-z did mean
that "most" developers and tools that deal with text files do respect the
ctrl-z standard. So, for about 30 years now anyone who has to deal with text
files will have learned that the end (EOF) character is a ctrl-z.

If you open up a text file created by access with a HEX editor, you WILL NOT
see that character. This is because DOS + access correctly sets the length
of this text file.


Now that we know the above, it means that your "target" system is messing
this up. You don't mention "how" those files are being tied together. You
also don't mention if the files are being transferred to another system? So,
if you using some uploading software or something like FTP that is likely
where this ctrl-z is appearing (or that software is ON PURPOSE) placing the
ctrl-z in that file.

If you are using ftp, then try using binary ftp as opposed to text.

It NOT likely that ms-access is placing a ctrl-z in the character stream.

Try typing in a text file manually using notepad. (or cut+paste one line
from the access export file) and test this file....you see again that
DOS/windows DOES NOT place a ctrl-z at the end of the file. However, any
type of "transfer" system you use is likely where that ctrl-z is being
introduced here...
(even a email client could wind up doing this).

You also don't mention what version of access you are using. It possible
that "older" versions of ms-access did append that ctrl-z. Simply open up
the text file using notepad and scroll to the LAST line of the file...if you
see square there...then that is the ctrl-z. If you see a "funny" char at the
end, then simply delete that little square ctrl-z and then see if the file
works.....

If there is no control-z at the end of the file...then as mentioned this
problem is occurring during upload or some other "transfer" process or some
"other" utility that is touching this file along the way (as mentioned,
often text type processing routines (programs) will often add a ctrl-z to
the end for compatibility with other operating systems).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top