Strange problem using Access processed files

I

Isis

I am reading the contents of a file - parsing it with an access function
- then writing out a new file which I feel should be identical to the
original but with a new name. My code is;

Dim str1 As String, str2 As String
Open "D:\Test.txt" For Input As #1
Do While Not EOF(1)
str1 = Input(1, #1)
str2 = str2 + str1
Loop
Close #1
Open "D:\email\Test1.txt" For Output As #1
Print #1, str2
Close #1

Test1.txt always ends up 2 bytes longer than the original - two
characters are added to the end of the file - 0D & OA - does anyone know
how to stop this happening ?

For clarity - in my actual application my output file will have been
processed and would not be the same as the input file - but these two
characters mess up what I need the output file for - which is a CSV
import into another program.

Any help wth this would be most helpful.

Thanks
 
D

Douglas J Steele

That would be a Carriage Return (0D) and a Line Feed (0A). That should be
pretty standard for text files.
 
I

Isis

That would be a Carriage Return (0D) and a Line Feed (0A). That should be
pretty standard for text files.

Thanks for reply Douglas - yes it may be standard for a text file but it is
not present in the source file but IS added to the target file - after this
addition my automated import using the target as the file to be imported
(csv format) fails - if I manually edit off the erroneous 0D & OA then the
import works - I urgently need to find a way of writing out a file using
Access that does not have these extra bytes added ( and anyway, why does
Access decide to add these ?).

Any further help much appreciated.

Thanks again
 
D

Douglas J Steele

Sorry, I don't understand why your CSV file won't import with a CR/LF in it.

Maybe you'll need to use the Put statement to write in Binary mode.
 
I

Isis

change
Print #1, str2

to
Print #1, str2;

Albert,

You seem to have the answer again - it seems to work for me. Can you
possible shed some light on the why it works so I can understand it better
? Thanks very much for the help.

Regards
 
A

Albert D.Kallal

Albert,
You seem to have the answer again - it seems to work for me. Can you
possible shed some light on the why it works so I can understand it better
? Thanks very much for the help.

Regards

Do you want the long version, or the short version of a answer?

Short version

the ";" means don't add a cr to the string

print #1, "abc"; "def";"hij";


Long version
In basic language, even going back to the ORIGINAL 1981 ibm pc, the syntax
for the basic print was

print #, "hello" ;

print # , " how " ;

print #, " are you"

if you follow the print command with a ";", then carriage return will be
output. The above 3 commands would thus produce a text file with

hello how are you

If you drop the ; (semi colon, then the text file would be

hello
how are
you

In fact, you used this quite a bit, as OFTEN the print command was sending
data to a printer..and not the screen!!!

However, for both screen output, and printer output...back in those days,
you used print a lot..and to suppress the next line...; was used.

So, the ; is simply a VERY VERY old basic convention that is about 30 years
old now...and still remains intact today.

Even as a young lad using my APPLE II before the IBM pc came out, the BASIC
language used that convention way back then.....

In fact, it warms my heart that I can give advice on some knowledge that
learned so very long ago. Most of what we learned way back then is not
applicable today..but that old trick still works today!!!

Thank you kindly for asking why.......as that feature brings back so very
many old fond memories of my first computer (a apple II).
 
I

Isis

Do you want the long version, or the short version of a answer?

Short version

the ";" means don't add a cr to the string

print #1, "abc"; "def";"hij";


Long version
In basic language, even going back to the ORIGINAL 1981 ibm pc, the
syntax for the basic print was

print #, "hello" ;

print # , " how " ;

print #, " are you"

if you follow the print command with a ";", then carriage return will
be output. The above 3 commands would thus produce a text file with

hello how are you

If you drop the ; (semi colon, then the text file would be

hello
how are
you

In fact, you used this quite a bit, as OFTEN the print command was
sending data to a printer..and not the screen!!!

However, for both screen output, and printer output...back in those
days, you used print a lot..and to suppress the next line...; was
used.

So, the ; is simply a VERY VERY old basic convention that is about 30
years old now...and still remains intact today.

Even as a young lad using my APPLE II before the IBM pc came out, the
BASIC language used that convention way back then.....

In fact, it warms my heart that I can give advice on some knowledge
that learned so very long ago. Most of what we learned way back then
is not applicable today..but that old trick still works today!!!

Thank you kindly for asking why.......as that feature brings back so
very many old fond memories of my first computer (a apple II).


Thanks very much for the help.

Regards
 

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