Cannot get file contents

I am having trouble getting the contents of a binary file
The file is saving fine, but it is empty for some reason
What is wrong ?
Public Sub SaveFile(txt As String)
Dim FileName As String
Dim FF As Integer
FF = FreeFile
FileName = GetPathToAppFolder & "\bWin64.dll"
Debug.Print FileName
Open FileName For Binary As #FF
     Put #FF, 1, txt 'Data
    Close #FF
End Sub

Public Function CheckFileContents() As Boolean
Dim txt As String
Dim FileName As String
Dim FF As Integer
FF = FreeFile
FileName = GetPathToAppFolder & "\bWin64.dll"
Debug.Print FileName
If FileExists(FileName) Then
MsgBox "yes"
End If
       Open FileName For Binary As #FF
          Get #FF, , txt
      Close #FF
      Debug.Print "txt " & txt
   
       Exit Function

End Function

Open in new window

isnoend2001Asked:
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.

sarabandeCommented:
you can't print binary data as text as the first binary zero character would terminate the output.

you need to print the data byte by byte for example as hex characters by using the Hex function.

Sara
0
isnoend2001Author Commented:
Thanks sarabande, but i don't know what you mean i have other save/opens that work just fine
0
sarabandeCommented:
but i don't know what you mean
if you open a binary file using a hex editor, you encounter bytes with value (code) from 0 to 255 (0x00 to 0xFF in hex notation).

not all of these codes are printable characters (see ascii and ansi chart tables). for example codes from 0 to 31 decimal are not printable and code 32 is a space character.

you can assign non-printable characters to a string, or read them from binary file, but when printing them you may see "odd" characters or nothing. the latter would happen if the string contains a binary zero character (or binary zero wide character if UNICODE). the string output would be terminated at the first zero character.

i have other save/opens that work just fine
if the files contain text, it could be fine.

you wrote text to the file but have it opened as binary. because of that the following applies:

For files opened in Binary mode, all of the Random rules apply, except:
•The Len clause in the Open statement has no effect. Put writes all variables to disk contiguously; that is, with no padding between records.
•For any array other than an array in a user-defined type, Put writes only the data. No descriptor is written.
•Put writes variable-length strings that are not elements of user-defined types without the 2-byte length descriptor. The number of bytes written equals the number of characters in the string.

because of that the string written is not length terminated (neither by descriptor nor by zero termination) and probably could not properly read by Get because of that.

if you want to read a text file you should write a text file and not a binary file or read a text file created by a text editor. if you want to read binary data you should read them byte by byte or into a byte array.

Sara
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
isnoend2001Author Commented:
Thanks
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.