Binary file access

I need to write some strings, line by line into a binary file, and later read back the same strings line by line from the same file.
I tried the following, but failed, can someone help?

Open "a.txt" For Binary Access Write As #1
 Write #1, "data1"
 Write #1, "data2"
Close #1
   
Open "a.txt" For Input Access Read As #1
   
Do While Not EOF(1)
   Line Input #1, TextLine
   'some process to store the string
Loop
   
Close #1
recceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cvidlerCommented:
When writing to a binary file you MUST include a vbCrLf when you want a new line to start. Also you should use variables to write to the file not constants.  eg.


open "a.txt" for binary access write as #1

MyVar$ = "data 1" + vbCrLf
put #1, , MyVar$
MyVar$ = "data 2" + vbCrLf
Put #1, , MyVar$

Close #1


Open "a.txt" For Input Access Read As #1
     
Do While Not EOF(1)
   Line Input #1, TextLine
   'some process to store the string
Loop
     
Close #1


PS: Why are you writing to a binary file if it is going to be a text file - you should open it as follows

Open "a.txt" For Output Access Write As #1

then you can use the code you have above! No need to worry about adding vbCrLf to each line...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.